Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth sometimes fails fetching profile for r_basicprofile and anything that requests public-profile-url #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,22 @@ Strategy.prototype.userProfile = function(accessToken, done) {
//LinkedIn uses a custom name for the access_token parameter
this._oauth2.setAccessTokenName("oauth2_access_token");

var strategy = this;
this._oauth2.get(this.profileUrl, accessToken, function (err, body, res) {
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
if (err) {
if(!strategy.profileUrl.match('public-profile-url')) {
return done(new InternalOAuthError('failed to fetch user profile', err));
} else { // Retry without requesting the field 'public-profile-url' which errors out if the user has disabled their public profile
strategy.profileUrl = strategy.profileUrl.replace('public-profile-url','');
strategy.profileUrl = strategy.profileUrl.replace(',,',',');
strategy.profileUrl = strategy.profileUrl.replace('(,','(');
strategy.profileUrl = strategy.profileUrl.replace(',)',')');

return strategy.userProfile(accessToken, function(err, profile) {
return done(err, profile);
});
}
}

try {
var json = JSON.parse(body);
Expand Down