Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this._oauth.get(uri.format(url), token, tokenSecret, function (err, body, res) {
if (err) {
if (err.data) {
try {
json = JSON.parse(err.data);
} catch (_) {}
}
if (json && json.errors && json.errors.length) {
var e = json.errors[0];
return done(new APIError(e.message, e.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 = 'twitter';
profile._raw = body;
profile._json = json;
// NOTE: The "X-Access-Level" header is described here:
// https://dev.twitter.com/oauth/overview/application-permission-model
// https://dev.twitter.com/oauth/overview/application-permission-model-faq
profile._accessLevel = res.headers['x-access-level'];
this._oauth.get('https://api.dropbox.com/1/account/info', token, tokenSecret, 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 Error(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 = Profile.parse(json);
profile.provider = 'dropbox';
profile._raw = body;
profile._json = json;
done(null, profile);
});
}
this._oauth.get(this._userProfileURL + '?user_id=' + params.user_id, token, tokenSecret, function (err, body, res) {
if (err) {
if (err.data) {
try {
json = JSON.parse(err.data);
} catch (_) {}
}
if (json && json.errors && json.errors.length) {
var e = json.errors[0];
return done(new APIError(e.message, e.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 = parse(json);
profile.provider = 'twitter';
profile._raw = body;
profile._json = json;
done(null, profile);
});
} else {