Created
October 13, 2011 11:04
-
-
Save nicalpi/1283982 to your computer and use it in GitHub Desktop.
Omniauth multiple facebook login strategy
This file contains hidden or 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
# initializers/devise.rb | |
config.omniauth :facebook, [APP_ID], [APP_SECRET] | |
config.omniauth :facebook_app1, [APP_ID], [APP_SECRET], :iframe => true, :scope => 'publish_stream,offline_access,email' | |
config.omniauth :facebook_app2, [APP_ID], [APP_SECRET], :iframe => true, :scope => 'publish_stream,offline_access,email' |
This file contains hidden or 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
= link_to "Main login with Facebook", user_omniauth_authorize_path(:facebook) | |
= link_to "Login inside Facebook APP 1", user_omniauth_authorize_path(:facebook_app1) | |
= link_to "Login inside Facebook APP 2", user_omniauth_authorize_path(:facebook_app2) |
This file contains hidden or 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
# Create multiples Omniauth facebook login in the same app | |
# See this post for more details | |
# http://wealsodocookies.com/posts/how-to-create-multiple-facebook-omniauth-strategies-for-the-same-application | |
# initializers/omniauth.rb | |
module OmniAuth::Strategies | |
class FacebookApp1 < Facebook | |
def name | |
:facebook_app2 | |
end | |
end | |
class FacebookApp2 < Facebook | |
def name | |
:facebook_app2 | |
end | |
end | |
end |
This file contains hidden or 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
# users/omniauthCallbacks.rb | |
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | |
def facebook | |
@user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user) | |
if @user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook" | |
sign_in_and_redirect @user, :event => :authentication | |
else | |
session["devise.facebook_data"] = env["omniauth.auth"] | |
redirect_to new_user_registration_url | |
end | |
end | |
def facebook_app1 | |
@user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user) | |
if @user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook" | |
sign_in @user, :event => :authentication | |
redirect_to "[FACEBOOK_APP1_URL]" | |
else | |
session["devise.facebook_data"] = env["omniauth.auth"] | |
redirect_to new_user_registration_url | |
end | |
end | |
def facebook_app2 | |
@user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user) | |
if @user.persisted? | |
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook" | |
sign_in @user, :event => :authentication | |
redirect_to "[FACEBOOK_APP2_URL]" | |
else | |
session["devise.facebook_data"] = 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