Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using omniauth to facebook connect existing user with different permissions

I'm using devise/omniauth to do facebook authentication and works great. However, I would like to add a flow where an existing (non-facebook) user has ability to connect his account with facebook. This would require different facebook permissions. so i can't seem to find two things

  1. how to use devise/omniauth to request facebook connect without logging out current user
  2. request different extended permissions from user (different from those specified in the devise configuration file)

any ideas? thanks

like image 597
katzmopolitan Avatar asked Oct 20 '11 14:10

katzmopolitan


1 Answers

Answer to 1 is pretty easy: just add a if path into the omniauth_callbacks_controller::process_callback method like this

  # If a user is signed in then he is trying to link a new account
    if user_signed_in?
      if authentication.persisted? # This was a linking operation so send back the user to the account edit page  
        flash[:success] = I18n.t "controllers.omniauth_callbacks.process_callback.success.link_account", 
                                :provider => registration_hash[:provider].capitalize, 
                                :account => registration_hash[:email]
      else
        flash[:error] = I18n.t "controllers.omniauth_callbacks.process_callback.error.link_account", 
                               :provider => registration_hash[:provider].capitalize, 
                               :account => registration_hash[:email],
                               :errors =>authentication.errors
      end  
      redirect_to edit_user_account_path(current_user)

This is what I do in my application and it works fine.

Regarding question 2 I do not know how to support 2 different facebook authentication configurations however I have hard time seeing how that is useful to users since they need a consistent experience across both path: "sign in using facebook" and "link your account to facebook". (If you still want to pursue this path one idea I would explore is to create a new facebook application with its independent keys and configuration...)

Hope this help.

like image 140
Matteo Melani Avatar answered Oct 25 '22 05:10

Matteo Melani