Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'passport-oauth1' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
Strategy.prototype.authenticate = function(req, options) {
// When a user denies authorization on Twitter, they are presented with a link
// to return to the application in the following format (where xxx is the
// value of the request token):
//
// http://www.example.com/auth/twitter/callback?denied=xxx
//
// Following the link back to the application is interpreted as an
// authentication failure.
if (req.query && req.query.denied) {
return this.fail();
}
// Call the base class for standard OAuth authentication.
OAuthStrategy.prototype.authenticate.call(this, req, options);
};
Strategy.prototype.authenticate = function(req, options) {
// When a user denies authorization on Twitter, they are presented with a link
// to return to the application in the following format (where xxx is the
// value of the request token):
//
// http://www.example.com/auth/twitter/callback?denied=xxx
//
// Following the link back to the application is interpreted as an
// authentication failure.
if (req.query && req.query.denied) {
return this.fail();
}
// Call the base class for standard OAuth authentication.
OAuthStrategy.prototype.authenticate.call(this, req, options);
};
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'];
function TrelloStrategy(options, verify) {
OAuth1Strategy.call(this, Object.assign({
requestTokenURL: 'https://trello.com/1/OAuthGetRequestToken',
accessTokenURL: 'https://trello.com/1/OAuthGetAccessToken',
userAuthorizationURL: 'https://trello.com/1/OAuthAuthorizeToken',
sessionKey: 'trello',
consumerKey: options.clientID,
consumerSecret: options.clientSecret
}, options), (req, accessToken, refreshToken, profile, done) => {
request(`https://api.trello.com/1/members/me?key=${options.clientID}&token=${accessToken}`,
(err, response, body) => {
if (err) return done(err);
const profile = JSON.parse(body);
const namePieces = profile.fullName.split(' ');
const result = { id: profile.id };
result[config.auth.columns.user.firstName] = namePieces.shift();
result[config.auth.columns.user.lastName] = namePieces.join(' ');
result[config.auth.columns.user.email] = null;
function TrelloStrategy(options, verify) {
options = options || {};
options.requestTokenURL = options.requestTokenURL || 'https://trello.com/1/OAuthGetRequestToken';
options.accessTokenURL = options.accessTokenURL || 'https://trello.com/1/OAuthGetAccessToken';
options.userAuthorizationURL = options.userAuthorizationURL || 'https://trello.com/1/OAuthAuthorizeToken';
options.sessionKey = options.sessionKey || 'trello';
OAuth1Strategy.call(this, options, (req, accessToken, refreshToken, profile, done) => {
request(
'https://api.trello.com/1/members/me?key='+options.consumerKey+'&token='+accessToken,
function (error, response, body) {
if(error) {
return done(error);
}
var profile = JSON.parse(body);
var namePieces = profile.fullName.split(' ');
verify(req, accessToken, refreshToken, {
id: profile.id,
firstName: namePieces.shift(),
lastName: namePieces.join(' '),
email: null
}, done);
}
);
return done(error);
}
var profile = JSON.parse(body);
var namePieces = profile.fullName.split(' ');
verify(req, accessToken, refreshToken, {
id: profile.id,
firstName: namePieces.shift(),
lastName: namePieces.join(' '),
email: null
}, done);
}
);
});
this.name = 'trello';
};
TrelloStrategy.prototype = OAuth1Strategy.prototype;
module.exports = {
translateProfile: (token, tokenSecret, profile, cb) => { cb(null, profile); },
strategy: TrelloStrategy
};
request(`https://api.trello.com/1/members/me?key=${options.clientID}&token=${accessToken}`,
(err, response, body) => {
if (err) return done(err);
const profile = JSON.parse(body);
const namePieces = profile.fullName.split(' ');
const result = { id: profile.id };
result[config.auth.columns.user.firstName] = namePieces.shift();
result[config.auth.columns.user.lastName] = namePieces.join(' ');
result[config.auth.columns.user.email] = null;
verify(req, accessToken, refreshToken, result, done);
}
);
});
this.name = 'trello';
};
TrelloStrategy.prototype = Object.create(OAuth1Strategy.prototype);
module.exports = {
translateProfile: (token, tokenSecret, profile, cb) => { cb(null, profile); },
strategy: TrelloStrategy,
packageName: 'passport-oauth1'
};
function Strategy(options, verify) {
options = options || {};
options.requestTokenURL = options.requestTokenURL || 'https://www.evernote.com/oauth';
options.accessTokenURL = options.accessTokenURL || 'https://www.evernote.com/oauth';
options.userAuthorizationURL = options.userAuthorizationURL || 'https://www.evernote.com/OAuth.action';
options.sessionKey = options.sessionKey || 'oauth:evernote';
OAuthStrategy.call(this, options, verify);
this.name = 'evernote';
}
function Strategy(options, verify) {
options = options || {};
options.requestTokenURL = options.requestTokenURL || 'https://api.dropbox.com/1/oauth/request_token';
options.accessTokenURL = options.accessTokenURL || 'https://api.dropbox.com/1/oauth/access_token';
var params = { oauth_callback: options.callbackURL };
options.userAuthorizationURL = options.userAuthorizationURL || 'https://www.dropbox.com/1/oauth/authorize?' + querystring.stringify(params);
options.sessionKey = options.sessionKey || 'oauth:dropbox';
OAuthStrategy.call(this, options, verify);
this.name = 'dropbox';
}
function Strategy(options, verify) {
options = options || {};
options.requestTokenURL = options.requestTokenURL || 'https://api.twitter.com/oauth/request_token';
options.accessTokenURL = options.accessTokenURL || 'https://api.twitter.com/oauth/access_token';
options.userAuthorizationURL = options.userAuthorizationURL || 'https://api.twitter.com/oauth/authenticate';
options.sessionKey = options.sessionKey || 'oauth:twitter';
OAuthStrategy.call(this, options, verify);
this.name = 'twitter';
this._userProfileURL = options.userProfileURL || 'https://api.twitter.com/1.1/account/verify_credentials.json';
this._skipExtendedUserProfile = (options.skipExtendedUserProfile !== undefined) ? options.skipExtendedUserProfile : false;
this._includeEmail = (options.includeEmail !== undefined) ? options.includeEmail : false;
this._includeStatus = (options.includeStatus !== undefined) ? options.includeStatus : true;
this._includeEntities = (options.includeEntities !== undefined) ? options.includeEntities : true;
}