ArkeologeN / node-linkedin

LinkedIn 2.0 wrapper in Node.js
MIT License
163 stars 79 forks source link

Invalid access token with oauth_token from Linkedin JS SDK #82

Closed dbeja closed 6 years ago

dbeja commented 6 years ago

Hi,

On the frontend I'm using Linkedin Javascript SDK to login the user in my application:

IN.User.authorize(function(response) { ..... });

Then I send the oauth_token that is on IN.ENV.auth.oauth_token to my nodejs service.

On my nodejs service I'm trying to use node-linkedin to get details about the user:

const linkedin = require('node-linkedin')('CLIENT_ID', 'CLIENT_SECRET');
const linkedinApi = linkedin.init(token);  // the oauth_token from above
linkedinApi.people.me(function(err, user) { .... }

But I always get "Invalid access token." error.

Am I doing something wrong? Can't I use this oauth_token to authorize my linkedin api calls?

ArkeologeN commented 6 years ago

Unfortunately no! You need to access_token instead of authorization code in order to call any endpoint.

dbeja commented 6 years ago

I found a way to make it work but couldn't find any documentation to support that, only some lost comments on the web.

Instead of adding an Authorization Bearer header, I use instead a oauth_token header with the token I get on frontend from IN.ENV.auth.oauth_token.

ArkeologeN commented 6 years ago

In that case, you may send me a pull request and I'll add that feature! would be awesome to have it supported :)

dbeja commented 6 years ago

I was about to do that but I noticed that already exists on the code :) Basically this option is when you choose oauth version 1.

If I initialize with these options I think it will work:


var linkedin = Linkedin.init({
    token: JS_TOKEN,
    type: 'server',
    version: 1
});