Devise + Omniauth - How to pass extra parameters along?

后端 未结 3 1422
孤独总比滥情好
孤独总比滥情好 2020-11-29 21:38

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 r

相关标签:
3条回答
  • 2020-11-29 22:08

    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! :)

    0 讨论(0)
  • 2020-11-29 22:18

    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.

    0 讨论(0)
  • 2020-11-29 22:23

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

    /users/auth/facebook?state=parameter
    

    You could send the parameter as a url form encoded json and then in the callback parse it.

    0 讨论(0)
提交回复
热议问题