Devise + Omniauth - How to pass additional parameters?

I have the ability to download / users / auth / facebook in my application to connect to facebook. I want to know where the request came from. Whether it was from a user who registers with facebook, or from an existing user who just wants to connect to facebook. Based on type, the answers are very different.

How can I pass a parameter while checking on omniauth. I tried:

/users/auth/facebook?connect_action=signup_connect_to_facebook 

But this connection_action parameter did not do this when he clicked the AuthenticationsController # Create button

Ideas? Thansk

+34
ruby-on-rails ruby-on-rails-3
Jul 11 2018-11-11T00:
source share
3 answers

You should use the options :params , as in

 omniauth_authorize_path(:user, :facebook, var: 'value', var2: 'value2' ) 

and then in the callback you can access request.env['omniauth.params'] to get the hash! :)

+92
Mar 08 2018-12-12T00:
source share

If the request is made from different pages of your application, you can check request.env ['omniauth.origin']. Omniauth automatically saves this variable.

Here is a more detailed explanation.

Regarding the transfer of user parameters, I tried to do this unsuccessfully. The workaround is to keep it in the session before contacting the provider, as described here .

Hope this helps you.

+8
Jul 13 2018-11-11T00:
source share

For facebook, use the "state" parameter and pass what you want, but don't forget the encoding.

 /users/auth/facebook?state=parameter 

You can send this parameter as json encoding and then parse it in a callback.

+1
Jan 10 '13 at
source share



All Articles