Created
March 3, 2014 14:41
-
-
Save tanraya/9326393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def authorize!(oauth_hash, user) | |
User::Oauth2Service.new(oauth_hash, user).workflow self do | |
# Account successfully created, or user successfully logged in. Now sign in user. | |
on_sign_in do |account, provider_title| | |
session.delete("omniauth.auth") | |
session.delete("provider_title") | |
if account.user.confirmed? | |
sign_in_user_and_redirect(account.user, provider_title) | |
else | |
redirect_to users_registration_done_path and return | |
end | |
end | |
# In some cases oauth2 provider does not provide required data (e.g. email) | |
# So here we request for required fields | |
on_invalid_credentials do |user, provider_title| | |
@user = user | |
@provider_title = provider_title | |
# Keep oauth hash in session | |
session["omniauth.auth"] = request.env["omniauth.auth"] | |
session["provider_title"] = @provider_title | |
render :new | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment