Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.provider.applicationByConsumerKey(requestParameters['oauth_consumer_key'], function(err, user) {
if(err) {
callback(new errors.OAuthProviderError('Invalid Consumer Key'), null);
} else {
if(user.consumer_key == null || user.secret == null) { callback(new errors.OAuthProviderError("provider: applicationByConsumerKey must return a object with fields [consumer_key, secret]")); return;}
// Ensure we don't have any hanging consumer keys
self.provider.cleanRequestTokens(requestParameters['oauth_consumer_key'], function(err, result) {
// If we have a user for this consumer key let's calculate the signature
var calculatedSignature = self.calculateSignature(method, protocol, url, path, requestParameters, user.token, user.secret);
// Check if the signature is correct and return a request token
if(calculatedSignature == requestParameters.oauth_signature || self.calculateSignatureGoogleWay(method, protocol, url, path, requestParameters, user.token, user.secret) == requestParameters.oauth_signature) {
self.provider.generateRequestToken(requestParameters.oauth_consumer_key, requestParameters.oauth_callback, function(err, result) {
if(err) {
callback(new errors.OAuthProviderError("internal error"), null);
} else {
if(result.token == null || result.token_secret == null) { callback(new errors.OAuthProviderError("provider: generateRequestToken must return a object with fields [token, token_secret]"), null); return;}
result['oauth_callback_confirmed'] = true;
callback(null, result);
}
this.provider.fetchAuthorizationInformation(username, token, function(err, application, user) {
if(application.title == null || application.description == null || user.token == null || user.username == null) { callback(new errors.OAuthProviderError("provider: applicationByConsumerKey must return a application object with fields [title, description] and a user object with fields [username, token]"), null); return;}
// Return the value to calling plugin
callback(err, application, user);
});
}
this.provider.applicationByConsumerKey(requestParameters['oauth_consumer_key'], function(err, user) {
if(err) {
callback(new errors.OAuthProviderError('Invalid Consumer Key'), null);
} else {
if(user.consumer_key == null || user.secret == null) { callback(new errors.OAuthProviderError("provider: applicationByConsumerKey must return a object with fields [consumer_key, secret]")); return;}
// Ensure we don't have any hanging consumer keys
self.provider.cleanRequestTokens(requestParameters['oauth_consumer_key'], function(err, result) {
// If we have a user for this consumer key let's calculate the signature
var calculatedSignature = self.calculateSignature(method, protocol, url, path, requestParameters, user.token, user.secret);
// Check if the signature is correct and return a request token
if(calculatedSignature == requestParameters.oauth_signature || self.calculateSignatureGoogleWay(method, protocol, url, path, requestParameters, user.token, user.secret) == requestParameters.oauth_signature) {
self.provider.generateRequestToken(requestParameters.oauth_consumer_key, requestParameters.oauth_callback, function(err, result) {
if(err) {
callback(new errors.OAuthProviderError("internal error"), null);
} else {
if(result.token == null || result.token_secret == null) { callback(new errors.OAuthProviderError("provider: generateRequestToken must return a object with fields [token, token_secret]"), null); return;}
result['oauth_callback_confirmed'] = true;
callback(null, result);
}
});
} else {
self.provider.validToken(requestParameters.oauth_token, function(err, token) {
if(err) {
callback(new errors.OAuthProviderError('Invalid / expired Token'), null);
} else {
if(token.access_token == null || token.token_secret == null) { callback(new errors.OAuthProviderError("provider: validToken must return a object with fields [access_token, token_secret]"), null); return;}
self.provider.validateNotReplay(requestParameters.oauth_token, requestParameters.oauth_timestamp, requestParameters.oauth_nonce, function(err, result) {
if(err) {
callback(new errors.OAuthUnauthorizedError('Invalid / used nonce'), null);
} else {
self.provider.applicationByConsumerKey(token.consumer_key, function(err, user) {
if(user.consumer_key == null || user.secret == null) { callback(new errors.OAuthProviderError("provider: applicationByConsumerKey must return a object with fields [token, secret]"), null); return;}
// If we have a user for this consumer key let's calculate the signature
var calculatedSignature = self.calculateSignature(method, protocol, url, path, requestParameters, token.token_secret, user.secret);
// Check if the signature is correct and return a access token
if(calculatedSignature == requestParameters.oauth_signature || self.calculateSignatureGoogleWay(method, protocol, url, path, requestParameters, token.token_secret, user.secret) == requestParameters.oauth_signature) {
// Fetch the user id to pass back
self.provider.userIdByToken(requestParameters.oauth_token, function(err, doc) {
if(doc.id == null) { callback(new errors.OAuthProviderError("provider: userIdByToken must return a object with fields [id]"), null); return;}
// Return the user id to the calling function
self.provider.applicationByConsumerKey(token.consumer_key, function(err, user) {
if(user.consumer_key == null || user.secret == null) { callback(new errors.OAuthProviderError("provider: applicationByConsumerKey must return a object with fields [token, secret]"), null); return;}
// If we have a user for this consumer key let's calculate the signature
var calculatedSignature = self.calculateSignature(method, protocol, url, path, requestParameters, token.token_secret, user.secret);
// Check if the signature is correct and return a access token
if(calculatedSignature == requestParameters.oauth_signature || self.calculateSignatureGoogleWay(method, protocol, url, path, requestParameters, token.token_secret, user.secret) == requestParameters.oauth_signature) {
// Fetch the user id to pass back
self.provider.userIdByToken(requestParameters.oauth_token, function(err, doc) {
if(doc.id == null) { callback(new errors.OAuthProviderError("provider: userIdByToken must return a object with fields [id]"), null); return;}
// Return the user id to the calling function
callback(null, doc);
});
} else {
callback(new errors.OAuthBadRequestError("Invalid signature"), null);
}
});
}
self.provider.userIdByToken(requestParameters.oauth_token, function(err, doc) {
if(doc.id == null) { callback(new errors.OAuthProviderError("provider: userIdByToken must return a object with fields [id]"), null); return;}
// Return the user id to the calling function
callback(null, doc);
});
} else {
this.provider.tokenByTokenAndVerifier(token, verifier, function(err, token) {
if(token.token == null || token.verifier == null) { callback(new errors.OAuthProviderError("provider: tokenByTokenAndVerifier must return a token object with fields [token, verifier]"), null); return;}
callback(err, token);
});
}
self.provider.generateAccessToken(requestParameters['oauth_token'], function(err, result) {
if(result.access_token == null || result.token_secret == null) { callback(new errors.OAuthProviderError("generateAccessToken must return a object with fields [access_token, token_secret]"), null); return; }
callback(null, result);
});
} else {
self.provider.generateRequestToken(requestParameters.oauth_consumer_key, requestParameters.oauth_callback, function(err, result) {
if(err) {
callback(new errors.OAuthProviderError("internal error"), null);
} else {
if(result.token == null || result.token_secret == null) { callback(new errors.OAuthProviderError("provider: generateRequestToken must return a object with fields [token, token_secret]"), null); return;}
result['oauth_callback_confirmed'] = true;
callback(null, result);
}
});
} else {
self.provider.generateRequestToken(requestParameters.oauth_consumer_key, requestParameters.oauth_callback, function(err, result) {
if(err) {
callback(new errors.OAuthProviderError("internal error"), null);
} else {
if(result.token == null || result.token_secret == null) { callback(new errors.OAuthProviderError("provider: generateRequestToken must return a object with fields [token, token_secret]"), null); return;}
result['oauth_callback_confirmed'] = true;
callback(null, result);
}
});
} else {