Open oleksii-makarov opened 9 years ago
Got the same issue. And it's strange, because it can be reproduced using only one specific account. With other accounts it works well.
I am having the same issue:
InternalOAuthError: failed to fetch user profile (status: 500 data: { "errorCode": 0, "message": "Internal API server error", "requestId": "P0V0VV6V4I", "status": 500, "timestamp": 1419763504192 }) at Strategy.userProfile (/Users/bartvanremortele/infinite/infinite-web/node_modules/passport-linkedin-oauth2/lib/oauth2.js:29:28) at passBackControl (/Users/bartvanremortele/infinite/infinite-web/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:124:9) at IncomingMessage.exports.OAuth2._executeRequest.request.on.callbackCalled (/Users/bartvanremortele/infinite/infinite-web/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth2/node_modules/oauth/lib/oauth2.js:143:7) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:943:16 at process._tickDomainCallback (node.js:463:13)
I'm having this exact issue. I've also notified my friends at LinkedIn about it. He says their API team is out for the holidays and will be back around the 5th...
Here is something you can try:
var request = require('request');
var qs = require('qs');
var oldRequest = strategy._oauth2._request;
strategy._oauth2._request = function (method, url, headers, post_body, access_token, callback) {
var body = qs.parse(post_body);
if (!body.grant_type || body.grant_type !== 'authorization_code') {
return oldRequest.apply(this, arguments);
}
console.log('DOING POST WITH BODY IN QS');
request.post({
url: url,
headers: headers,
qs: body,
}, function (err, r, body) {
callback(err, body, r);
});
};
This was reported in the forums few months ago and I am not sure If they have fixed. At some point the http "POST" required to exchange the authorization code per access token stopped accepting the params in the body or it works some times. Sending the parameters in querystring seems to work for us.
To be honest, do not trust Linkedin oauth. This has happened before, the api has been down for a week once, but if this works for you I will be happy to hardcode it on the module itself.
@jfromaniello
Where should i put this code?
@boris-petrov1214 yes, try this with the instance of the strategy.. like:
var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;
var request = require('request');
var qs = require('qs');
//initialize the strategy as always, with options and callback.
var strategy = new new LinkedInStrategy(options, callback);
//monkeypatch oauth2._request
var oldRequest = strategy._oauth2._request;
strategy._oauth2._request = function (method, url, headers, post_body, access_token, callback) {
var body = qs.parse(post_body);
if (!body.grant_type || body.grant_type !== 'authorization_code') {
return oldRequest.apply(this, arguments);
}
console.log('DOING POST WITH BODY IN QS');
request.post({
url: url,
headers: headers,
qs: body,
}, function (err, r, body) {
callback(err, body, r);
});
};
//configure passport to use this strategy:
passport.use(strategy);
Make sense? If this fix your issue I will do it in the strategy itself.
Sorry for being late.
This is the error from linkedin with another error message.
DOING POST WITH BODY IN QS
failed to fetch user profile (status: 500 data: {
"errorCode": 0,
"message": "Internal API server error",
"requestId": "G7LOSWG3MQ",
"status": 500,
"timestamp": 1420558050108
})
at /Users/justinchambers/Documents/webapps/oddjob/node_modules/passport-linkedin-oauth2/lib/oauth2.js:29:28
at passBackControl (/Users/justinchambers/Documents/webapps/oddjob/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth/node_modules/oauth/lib/oauth2.js:109:9)
at IncomingMessage.
I am pretty sure that this bug occurs when we specify the scope (permission) as r_fullprofile If i specify the permission as r_basicprofile, then the bug is gone. However I need r_fullprofile permission because i need to fetch skills etc...
I am thinking about the one solution, but not sure it's doable.
After deep investigation I found that for those strange profiles "suggestions" field lead to linkedin Internal Error. So in my case solution is to remove that field from "r_fullprofile" permission in oauth2.js . Is there any way to prevent fetching this data on auth callback? Or modify fields to fetch on authentication? For example I need only email on login, but lib tries to fetch all possible data for permissions.
I can make a fork and just comment that "suggestions" field, but would it be the right solution?
This issue seems to be resolved. I had an ongoing issue since late december but today I managed to login with oauth2 into our application using my linkedin account which previously gave an API error.
Still facing the same issue for r_fullprofile scope. This is for some specific linkedin login credentials .
Can anyone tell me why the issue is for only specific linkedin users.
Using passport-linkedin-oauth2 Version 1.1.1
AndyBimal, actual error occurs on linkedin server. Some profiles have broken fields in linkedin db so it leads to such behavior. In my case it was "suggestions" field and I just commented this field in my own fork. But seems like its already fixed in 1.2.1 version of passport-linkedin-oauth2
I can confirm that removing 'suggestions' from r_fullprofile fixes this problem as suggested by @aromanyuk
Was this resolved? Got error:
{ InternalOAuthError: failed to fetch user profile
at /var/www/app/node_modules/passport-linkedin-oauth2/lib/oauth2.js:29:28
at passBackControl (/var/www/app/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage.<anonymous> (/var/www/app/node_modules/oauth/lib/oauth2.js:157:7)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:973:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
name: 'InternalOAuthError',
message: 'failed to fetch user profile',
oauthError:
{ statusCode: 500,
data: '{\n "errorCode": 0,\n "message": "Internal service error",\n "requestId": "YU1WDLQCJC",\n "status": 500,\n "timestamp": 1493370609594\n}' } }
I am seeing the same issue. I am tempted to try @aromanyuk's solution: create a fork of the repo and comment out the suggestions
field in the /lib/oauth2.js
file. Haven't tried that yet though.
Strange that this issue has been around so long with no one fixing it.
If you have issues using the 'r_basicprofile' and 'r_emailaddress', you can use my fork (https://github.com/catrielmuller/passport-linkedin-oauth2), the issue its produced by the field 'current-share'. Probably its a problem on the Linkedin API, but... i cant solved there :smiley:
I just ran into the same problem with 'current-share' as @catrielmuller for the last couple of hours. Instead of using a fork, I ended up just specifying the profileFields array in the options.
I removed the 'current-share' field, which was causing some 500 errors, and I kept all the other fields included when using the r_basicprofile scope.
profileFields: [ 'email-address', 'id', 'first-name', 'last-name', 'picture-url', 'picture-urls::(original)', 'formatted-name', 'maiden-name', 'phonetic-first-name', 'phonetic-last-name', 'formatted-phonetic-name', 'headline', 'location:(name,country:(code))', 'industry', 'distance', 'relation-to-viewer:(distance,connections)', 'num-connections', 'num-connections-capped', 'summary', 'specialties', 'positions', 'site-standard-profile-request', 'api-standard-profile-request:(headers,url)', 'public-profile-url' ]
@hunton You beat me on this. No need to fork. I came here to say EXACTLY that.
Some additional thoughts:
profileFields
as @hunton mentioned does not exempt you from specifying the scope
too. The only difference is that passport-linkedin-oauth2
will only fetch the specified fields.passport-linkedin-oauth2
will, by default, ask for all fields and the LinkedIn API isn't properly architectured to handle that in cases they suddenly decide to change fields. You'll save yourself from future inconsistencies in fields you don't acually use.Here's my setup:
{
profileFields: [
"formatted-name",
"headline",
"id",
"public-profile-url",
"email-address",
"location",
],
scope: ["r_basicprofile", "r_emailaddress"],
}
Works like a charm.
@andrerpena and @hunton your suggestions worked. For anyone wondering where to specify options, do it when defining your linkedin strategy e.g:
passport.use(new LinkedInStrategy({
clientID: process.env.LINKEDIN_CLIENT_ID,
clientSecret: process.env.LINKEDIN_CLIENT_SECRET,
callbackURL: process.env.LINKEDIN_CALLBACK_URL,
profileFields: [
"first-name",
"last-name",
"email-address",
"headline",
"summary",
"industry",
"picture-url",
"positions",
"public-profile-url",
"location"
],
scope: ['r_basicprofile', 'r_emailaddress'],
state: true,
passReqToCallback: true
}, function(req, accessToken, refreshToken, profile, done) { ...
@kunal-mandalia yes, that's where to put this. https://developer.linkedin.com/docs/fields/basic-profile has the list of fields that should work if anyone is wondering
@zoellner as you say... Should be, hehehe
Confirm, this is the solution. Works for me too.
Looks like LinkedIn changed something from their side that breaks the integration. But setting profile fields works.
Confirm, the solution outlined by @hunton and @andrerpena worked for me also. This error had been persistent in production for us for over a year, and now we have had no more occurrences after a few days of trying the solution above. Thanks to all those involved to investigate this and fix it!
Thanks, this profile fields option solved it for me. I was banging my head to get picture url, location and other basic profile information from my asp.net core 2.0 website. I was working with Signin-Linkedin and was trying to get Authorization Code leading to Access Token for further api calls . Getting profile fields is working like a charm that's perfect but is there any way to get Authorization Code leading to AccessToken too?
Thanks, it solved my issue. I added the id
field to fetch the profile ID as well which may be important if your auth is using the profile id.
I have had this problem with the API of companies V1. it worked perfectly until yesterday. I m using this script in R:
https://api.linkedin.com/v1/company-search:(companies:(id,name,emailDomains,universal-name,website-url,industries,status,logo-url,blog-rss-url,twitter-id,employee-count-range,specialties,locations:(description,contact-info,is-headquarters,address:(country-code,city)),description,stock-exchange,founded-year,end-year,num-followers))?oauth2_access_token="MYTOKEN"&keywords=((cardiovascular OR cardiac OR coronary OR apnhea OR apnea OR apnoea) AND prevention)&start=50
The api works perfectly until I obtain the number 50
I hope someone can help me
Cheers
This is also failing for me... My request is as follows:
{
scope: ['r_emailaddress', 'r_basicprofile'],
profileFields: ['email-address', 'id', 'first-name', 'last-name', 'public-profile-url'],
clientID: env('LINKEDIN_CLIENT_ID'),
clientSecret: env('LINKEDIN_CLIENT_SECRET'),
callbackURL
}
And I am getting the error: failed to fetch user profile
After the above solution fixed it for me (see my previous message) we are suddenly seeing issues again - Internal Server Error
. Simply trying to log in again works. Error happening sporadically. Anyone else seeing this happening recently?
anyone does know how to solve this error on Lock ?
I've gone trough the same problems and the easiest solution for me was stop allowing users to login with Linkedin.
@rubenanapu I don't see a solution in what you said
I tried the solutions mentioned in this thread but I am still facing the same issue. Following is the error snippet.
{ InternalOAuthError: failed to fetch user profile
at /home/ubuntu/www/recruiter-web/node_modules/passport-linkedin-oauth2/lib/oauth2.js:29:28
at passBackControl (/home/ubuntu/www/recruiter-web/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage.<anonymous> (/home/ubuntu/www/recruiter-web/node_modules/oauth/lib/oauth2.js:157:7)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
name: 'InternalOAuthError',
message: 'failed to fetch user profile',
oauthError:
{ statusCode: 500,
data: '{\n "errorCode": 0,\n "message": "Internal API server error",\n "requestId": "MSYLETXOVR",\n "status": 500,\n "timestamp": 1551148869085\n}' } }
I am using the following Linkedin Strategy.
passport.use('linkedin-auths', new LinkedInStrategy({
clientID: config['social']['linkedin']['clientId'],
clientSecret: config['social']['linkedin']['secret'],
callbackURL: config['social']['linkedin']['callbackURL'],
scope: ['r_emailaddress', 'r_basicprofile'],
profileFields: [
"id",
"picture-url",
"public-profile-url",
"headline"
],
passReqToCallback: true
}, async function(req, accessToken, refreshToken, params, profile, done){
// some application logic
}));
Did someone find the fix for this? We are facing this error on production and there seems to be no solution so far.
@5aurabh Same here tried to do the solutions mentioned above, but still getting the error. What about you, have you solved the problem yet?
@cjh9 @5aurabh same here, we tried to do this solutions but not work. any alternative solutions for it?????????
@cjh9 @mimrank No luck so far.
@5aurabh, @mimrank This repo works https://github.com/sokratisvidros/passport-linkedin-oauth2, linkedin have changed their api and version. Se alson https://github.com/auth0/passport-linkedin-oauth2 (this one is not working yet...)
@cjh9 Tried sokratisvidros' repo and still couldn't get it to work. Any ideas on how to fix the "failed to fetch user profile" issue?
@5aurabh, @mimrank This repo works https://github.com/sokratisvidros/passport-linkedin-oauth2, linkedin have changed their api and version. Se alson https://github.com/auth0/passport-linkedin-oauth2 (this one is not working yet...)
yes, first one work
@cjh9 Tried sokratisvidros' repo and still couldn't get it to work. Any ideas on how to fix the "failed to fetch user profile" issue?
LinkedIn's api request calls have changed with OAuth2.0 from 1 May 2019. https://github.com/sokratisvidros/passport-linkedin-oauth2 has updated the repo (so this one works) but hasn't yet merged it. Kudos @cjh9 @mimrank!
failed to fetch user profile (status: 500 data: { "errorCode": 0, "message": "Internal API server error", "requestId": "UZ932MLF2E", "status": 500, "timestamp": 1418143155363 }) at /app/node_modules/passport-linkedin-oauth2/lib/oauth2.js:29:28 at passBackControl (/app/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth/node_modules/oauth/lib/oauth2.js:109:9) at IncomingMessage. (/app/node_modules/passport-linkedin-oauth2/node_modules/passport-oauth/node_modules/oauth/lib/oauth2.js:128:7) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:943:16 at process._tickCallback (node.js:419:13)