I am using OAuth to a provider (LinkedIn).
I want to be able to pass parameters so that when someone signs-up, I can add some additional values at the time the new User is created (I am using Devise).
But how do I do that?
It looks like the link goes to the provider, which then makes a callback to my application. How can I pass parameters from that link?
First, it is necessary to acquire OAuth 2.0 client credentials from API console. Then, the access token is requested from the authorization server by the client. It gets an access token from the response and sends the token to the API that you wish to access. You must send the user to the authorization endpoint at the beginning.
OAuth says absolutely nothing about the user, nor does it say how the user proved their presence or even if they're still there. As far as an OAuth client is concerned, it asked for a token, got a token, and eventually used that token to access some API.
OAuth 2.0 - Obtaining an Access Token 1 First, it is necessary to acquire OAuth 2.0 client credentials from API console. 2 Then, the access token is requested from the authorization server by the client. 3 It gets an access token from the response and sends the token to the API that you wish to access. More ...
User Authentication with OAuth 2.0 The OAuth 2.0 specification defines a delegation protocol that is useful for conveying authorization decisions across a network of web-enabled applications and APIs. OAuth is used in a wide variety of applications, including providing mechanisms for user authentication.
If you add GET
style params to the authentication url they will be available in the callback via the Rails request.env
object under the omniauth.params
key. For example
If you authenticate via:
link_to "Log In", "/auth/linkedin?foo=bar"
In the controller method mapped to GET /auth/:provider/callback
you will have:
request.env['omniauth.params'] == { "foo" => "bar" }
Answer was a bit late, but I hope it helps someone.
The easy way to do this is to set the parameters in the session, then access them in the callback.
In your action that redirects to the provider:
session[:additional] = additional_data_hash
In the action that handles the callback from the provider:
data = session.delete(:additional)
Use delete
to ensure your session remains small for subsequent requests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With