0
0
Ruby on Railsframework~10 mins

OAuth integration basics in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add the OmniAuth middleware for GitHub OAuth.

Ruby on Rails
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :github, [1], 'your_client_secret'
end
Drag options to blanks, or click blank then click option'
AENV['GITHUB_CLIENT_ID']
Bgithub_client_id
Cclient_id
DGITHUB_ID
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding the client ID directly in code.
Using incorrect variable names.
2fill in blank
medium

Complete the controller method to handle the OAuth callback and get the user's info.

Ruby on Rails
def github
  auth = request.env['omniauth.auth']
  user_info = auth[1]
  # Use user_info for login or signup
end
Drag options to blanks, or click blank then click option'
A['extra']
B['credentials']
C['info']
D['user']
Attempts:
3 left
💡 Hint
Common Mistakes
Accessing wrong keys like 'credentials' or 'extra' for user info.
Using symbols instead of strings for keys.
3fill in blank
hard

Fix the error in the route to correctly handle the OAuth callback.

Ruby on Rails
get '/auth/github/callback', to: '[1]#github'
Drag options to blanks, or click blank then click option'
Asessions
Bsession
Cauth
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular 'session' instead of 'sessions'.
Pointing to unrelated controllers like 'users' or 'auth'.
4fill in blank
hard

Fill both blanks to create a hash of user data from the OAuth info.

Ruby on Rails
user_data = {
  name: auth[1][:name],
  email: auth[2][:email]
}
Drag options to blanks, or click blank then click option'
A['info']
C['credentials']
D['extra']
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys like 'credentials' or 'extra' here.
Trying to use symbols instead of strings.
5fill in blank
hard

Fill all three blanks to complete the User model method that finds or creates a user from OAuth data.

Ruby on Rails
def self.from_omniauth(auth)
  where([1]: auth[:uid], provider: auth[:provider]).first_or_create do |user|
    user.email = auth[:info][[2]]
    user.name = auth[:info][[3]]
  end
end
Drag options to blanks, or click blank then click option'
Auid
Bemail
Cname
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'uid' for lookup.
Mixing up email and name keys.