Ruby on Rails: Integration with Authlogic Facebook: Linking accounts with user input instead of automatically using an email address

I am developing a web application in Ruby on Rails. I use authlogic for authentication. My site has its own logins, but I hope to use Facebook as well. I tried authlogic_facebook_connect (using Facebooker). After a lot of hiccups (the documents were not really saved completely), I really got authlogic_facebook_connect to work, and that's all right. By default, the "connect" behavior works fine when I come across users who have never used the site before, but this leads to a lot of duplicate logins for people who use different email addresses for Facebook and my site. Here is what I want:

When a user clicks the Facebook Connect button (and after they go through the Facebook authorization step by clicking "Allow"), I want a window to appear to ask the user if they want to connect to an existing account on my site or if they want to automatically create an account for them.

If they want it to be automatically generated for them, we are good and we act fine, but if - on the other hand - they want to link their Facebook account to the account on my site, I really want them to enter their local credentials and finding the right account. In other words, I don’t want my decision to automatically determine which account looks like the right one, I want the user to do this.

Is there any gem / plugin / quick hack that will allow me to disable this using authlogic_facebook_connect or OAuth or something else?

- david

+3
source share
1 answer

- , , , , , oauth2.

/.

1) " Facebook",

def to_facebook
    options = {
      :redirect_uri => facebook_callback_url,
      :scope => "email,publish_stream" # whatever you want to do
    }
    client = OAuth2::Client.new(FACEBOOK_API_KEY, FACEBOOK_API_SECRET, :site => FACEBOOK_API_SITE)

    redirect_to client.web_server.authorize_url(options)
end

2) facebook , facebook , facebook_callback_url, :

def facebook_callback
    client = OAuth2::Client.new(FACEBOOK_API_KEY, FACEBOOK_API_SECRET, :site => FACEBOOK_API_SITE)
    access_token = client.web_server.get_access_token(params[:code], :redirect_uri => facebook_callback_url)

    do_my_custom_user_association(access_token)
end

, do_my_custom_user_association, current_user, authlogic, - , , , . , , facebook.

, , (, facebook_callback error_reason, get_acccess_token ), oauth2 , .

. http://developers.facebook.com/docs/authentication/, - oauth2 .

+3

Source: https://habr.com/ru/post/1781715/


All Articles