Omniauth Support
This commit is contained in:
parent
4ce034ca65
commit
a64aff2f1c
20 changed files with 195 additions and 61 deletions
|
@ -9,7 +9,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
error ||= env["omniauth.error.type"].to_s
|
||||
error.to_s.humanize if error
|
||||
end
|
||||
|
||||
|
||||
def ldap
|
||||
# We only find ourselves here if the authentication to LDAP was successful.
|
||||
info = request.env["omniauth.auth"]["info"]
|
||||
|
@ -20,4 +20,34 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
sign_in_and_redirect @user
|
||||
end
|
||||
|
||||
Settings.omniauth_providers.each do |provider|
|
||||
define_method provider['name'] do
|
||||
handle_omniauth
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_omniauth
|
||||
oauth = request.env['omniauth.auth']
|
||||
provider, uid = oauth['provider'], oauth['uid']
|
||||
|
||||
if current_user
|
||||
# Change a logged-in user's authentication method:
|
||||
current_user.uid = uid
|
||||
current_user.provider = provider
|
||||
current_user.save
|
||||
redirect_to profile_path
|
||||
else
|
||||
@user = User.find_by_provider_and_uid(provider, uid)
|
||||
|
||||
if @user
|
||||
sign_in_and_redirect @user
|
||||
else
|
||||
flash[:notice] = "There's no such user!"
|
||||
redirect_to new_user_session_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue