Complete the code to add the OmniAuth middleware for GitHub OAuth.
Rails.application.config.middleware.use OmniAuth::Builder do provider :github, [1], 'your_client_secret' end
You need to use the environment variable holding your GitHub client ID for security and flexibility.
Complete the controller method to handle the OAuth callback and get the user's info.
def github auth = request.env['omniauth.auth'] user_info = auth[1] # Use user_info for login or signup end
The user information is stored under the 'info' key in the auth hash.
Fix the error in the route to correctly handle the OAuth callback.
get '/auth/github/callback', to: '[1]#github'
The controller handling the OAuth callback is usually named SessionsController, so the route should point to 'sessions#github'.
Fill both blanks to create a hash of user data from the OAuth info.
user_data = {
name: auth[1][:name],
email: auth[2][:email]
}The 'info' key holds the user data, accessed as auth['info'][:name] and auth['info'][:email].
Fill all three blanks to complete the User model method that finds or creates a user from OAuth data.
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
The method looks up users by uid and provider, then sets email and name from the info hash.