Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self._oauth2.get(self._profileURL, accessToken, function(err, body) {
let json;
if (err) {
return done(new InternalOAuthError('Failed to fetch user profile', err));
}
try {
json = JSON.parse(body);
} catch (ex) {
return done(new Error('Failed to parse user profile'));
}
const profile = {
id: String(json.id),
username: json.username,
displayName: json.name,
emails: [{value: json.email}],
// jshint camelcase: false
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
avatarUrl: json.avatar_url,
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
var json;
if (err) {
if (err.data) {
try {
json = JSON.parse(err.data);
} catch (_) {}
}
if (json && json.error && json.error.message) {
return done(new GooglePlusAPIError(json.error.message, json.error.code));
} else if (json && json.error && json.error_description) {
return done(new UserInfoError(json.error_description, json.error));
}
return done(new InternalOAuthError('Failed to fetch user profile', err));
}
try {
json = JSON.parse(body);
} catch (ex) {
return done(new Error('Failed to parse user profile'));
}
var profile;
switch (self._userProfileFormat) {
case 'openid':
profile = OpenIDProfile.parse(json);
break;
default: // Google Sign-In
profile = GooglePlusProfile.parse(json);
break;
callbackURL: 'http://www.example.com/callback',
clientID: 'dummy',
clientSecret: 'secret',
tokenURL: 'http://www.example.com/token',
passReqToCallback: true
};
const strategy3: PassportStrategy = new OAuth2Strategy(strategyOptions2, verifyFunction3);
const strategy4: Strategy = new Strategy(strategyOptions2, verifyFunction4);
const err1 = new AuthorizationError('Description', 'invalid_request', undefined);
const err2 = new TokenError(undefined, 'invalid_request', undefined);
const err3 = new InternalOAuthError('Hello', {});
function (err, body, res) {
if (err) {
return done(new InternalOAuthError('failed to fetch user profile', err))
}
try {
var json = JSON.parse(body)
var profile = {
provider: 'microsoft',
name: {}
}
profile.id = json.id
profile.displayName = json.displayName
profile.name.familyName = json.surname
profile.name.givenName = json.givenName
profile.emails = [{ type: 'work', value: json.mail }]
profile._raw = body
profile._json = json
.fail(function(error) {
done(
new OAuth2Strategy.InternalOAuthError(
'Failed to fetch user profile',
error
)
);
});
});
this._oauth2.get(url, accessToken, function (error, body, res) {
if (error) return done(new InternalOAuthError('Failed to fetch user profile', error));
try {
var json = JSON.parse(body),
profile = {
provider: 'facebook',
id: json.id,
displayName: json.name || '',
name: {
familyName: json.last_name || '',
givenName: json.first_name || '',
middleName: json.middle_name || ''
},
gender: json.gender || '',
emails: [{
value: json.email || ''
}],
this._oauth2.get(this._profileUrl, accessToken, function(err, body, res) {
var json
if (err) {
return done(new InternalOAuthError('Failed to fetch current user', err))
}
try {
json = JSON.parse(body)
} catch (ex) {
return done(new Error('Failed to parse current user', ex))
}
var profile = json
profile.provider = 'veritone'
profile.oauthToken = accessToken
return done(null, profile)
})
};
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
var json;
if (err) {
if (err.data) {
try {
json = JSON.parse(err.data);
} catch (_) {}
}
if (json && json.error) {
return done(new LiveConnectAPIError(json.error.message, json.error.code));
}
return done(new InternalOAuthError('Failed to fetch user profile', err));
}
try {
json = JSON.parse(body);
} catch (ex) {
return done(new Error('Failed to parse user profile'));
}
var profile = Profile.parse(json);
profile.provider = 'windowslive';
profile._raw = body;
profile._json = json;
done(null, profile);
});
};
this._oauth2.get(this._userProfileURL, accessToken, function (err, body, res) {
var json;
if (err) {
if (err.data) {
try {
json = JSON.parse(err.data);
} catch (_) {}
}
if (json && json.message) {
return done(new APIError(json.message));
}
return done(new InternalOAuthError('Failed to fetch user profile', err));
}
try {
json = JSON.parse(body);
} catch (ex) {
return done(new Error('Failed to parse user profile'));
}
var profile = Profile.parse(json);
profile.provider = 'github';
profile._raw = body;
profile._json = json;
if (self._scope && self._scope.indexOf('user:email') !== -1) {
self._oauth2._request('GET', self._userProfileURL + '/emails', { 'Accept': 'application/vnd.github.v3+json' }, '', accessToken, function(err, body, res) {