Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise + Omniauth - How to pass extra parameters along?

I have the ability in the app to load /users/auth/facebook to connect to facebook. I want to be able to know where the request came from. Whether it was from a user who is registering with facebook, or a existing user who simply wants to connect with facebook. Based on the type, the responses are very different.

How can I pass a param along to omniauth when authenticating. I tried doing:

/users/auth/facebook?connect_action=signup_connect_to_facebook 

But that connect_action param didn't make it when it hit AuthenticationsController#Create

Ideas? Thansk

like image 390
AnApprentice Avatar asked Jul 11 '11 23:07

AnApprentice


2 Answers

You have to use the :params options, as in

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

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

like image 161
fuzzyalej Avatar answered Sep 18 '22 15:09

fuzzyalej


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

Here is a more detailed explanation

As far as passing custom parameters, I have tried to do this unsuccessfully. The workaround is to store it in the session before going to the provider as explained here.

Hope this helps you.

like image 22
e3matheus Avatar answered Sep 18 '22 15:09

e3matheus