Omniauth Support

This commit is contained in:
Florian Unglaub 2012-08-03 17:27:39 +02:00
parent 4ce034ca65
commit a64aff2f1c
20 changed files with 195 additions and 61 deletions

View file

@ -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