Skip to content

Instantly share code, notes, and snippets.

@ParthivPatel-BTC
Created September 10, 2019 01:58
Show Gist options
  • Save ParthivPatel-BTC/ee720582fc89c49cf64be5222704e690 to your computer and use it in GitHub Desktop.
Save ParthivPatel-BTC/ee720582fc89c49cf64be5222704e690 to your computer and use it in GitHub Desktop.
OmniauthCallbacksController
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
auth = request.env["omniauth.auth"]
@user.access_token = auth.credentials.token
@user.expires_at = auth.credentials.expires_at
@user.refresh_token = auth.credentials.refresh_token
@user.save!
sign_in(@user)
redirect_to tasks_path
else
session["devise.google_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment