Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkedIn verify user auth token server side

after 1 day of research, I've ended with the following issue. I'm building an web app with ember.js and currently I'm implementing LinkedIn login, using linkedin javascript sdk. The problem that I have is that after I recieve user information (token, email, first name and etc) I need to verify this token on server side in order to grand session. Unfortunately, the documentation is not very clear for me. I can access token ( or kind of a token ) using IN.ENV.auth, but when I try to validate one from both of them, I recieve "invalid request". On the server side I'm using node and a sample code look like that:

var request = require('request');
var options = {
    url: 'https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=TOKEN_RECIEVED_THROUGH_IN.ENV.auth&redirect_uri=my-domain&client_id=API_CLIENT_ID&client_secret=API_SECRET_KEY'
};
request(options,function(err,res,body){
    console.log(body);
});

The response from the sdk is like that:

anonymous_expires_in: 1800
anonymous_token: "4u948tas123asfK9DJx9HFYJgcsBFlhIFu93gG"
api_key: "API_KEY"
is_set_client_auth_cookie: false
member_id: "4a13sdasFeD"
oauth_expires_in: 1800
oauth_token: "66Dy9V123lL7H823ddl-5L-KVmg184k0dhAaS"

Thanks in advance.

like image 628
Anton Dimitrov Avatar asked Mar 11 '15 13:03

Anton Dimitrov


People also ask

How do I validate access tokens?

The high-level overview of validating an access token looks like this: Retrieve and parse your Okta JSON Web Keys (JWK), which should be checked periodically and cached by your application. Decode the access token, which is in JSON Web Token format. Verify the signature used to sign the access token.

How do I get my LinkedIn API token?

In the POST field, enter https://www.linkedin.com/oauth/v2/accessToken as the POST URL. Note that as you specify parameters, Postman will build the request URL for you. Assuming everything went well, you will now see your access token displayed in the response! By default, your access token will be good for 60 days.


1 Answers

It seems that if you just add header oauth_token to GET request, it works:

GET /v1/people/~:(id,firstName,lastName,siteStandardProfileRequest,picture-url,email-address)?format=json HTTP/1.1
Host: api.linkedin.com
oauth_token: your-token-here

P.S. But I'm not sure it will work continuously because the documentation I have not read

like image 89
ktretyak Avatar answered Nov 16 '22 00:11

ktretyak