LinkedIn: Javascript Token and validate user in server

Viewed 381

I have been reading a lot of questions/answers about the LinkedIn login through javascript login and the validation of the user from backend. But I didn't find a solution that worked with current API.

I understood that the JS token is not the same as the Oauth Token and I don't need to save the token for the future use, I only need to validate the user before the signup on the website.

Once the user is authenticated, I'm going to request the basic profile user and api-standard-profile-request

IN.API.Profile("me").fields(
        'id', 'first-name', 'last-name', 'email-address', 'api-standard-profile-request')

The apiStandardProfile returns me an object with an url (like this https://api.linkedin.com/v1/people/{id_user}) and an array with headers (like this name: "x-li-auth-token", value: "name:xxxx"). I haven't find in the official docs how to use this, but I receive every time an "Authentication Failed" with status code 200.

So, do I need to rewrite the authentication flow with Oauth2.0, or can I continue to use the Javascript login?

Thanks

P.S.: I found and read the old documentation from this old topic https://web.archive.org/web/20141028192415/https://developer.linkedin.com/documents/exchange-jsapi-tokens-rest-api-oauth-tokens.

2 Answers

I've had the same problem and the only way I found to use the JS token was to use the header oauth_token instead of an Authorization Bearer header when requesting something with Rest API:

POST https://api.linkedin.com/v1/people/~:(id,firstName,lastName,picture-url,email-address)?format=json
Headers {
  'oauth_token': JS_TOKEN
}

The JS_TOKEN I'm reading on frontend from IN.ENV.auth.oauth_token.

Related