function InternalOAuthError(message, err) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.oauthError = err; }
n/a
function OAuth2Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = undefined; } options = options || {}; if (!verify) { throw new TypeError('OAuth2Strategy requires a verify callback'); } if (!options.authorizationURL) { throw new TypeError('OAuth2Strategy requires a authorizationURL option'); } if (!options.tokenURL) { throw new TypeError('OAuth2Strategy requires a tokenURL option'); } if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); } passport.Strategy.call(this); this.name = 'oauth2'; this._verify = verify; // NOTE: The _oauth2 property is considered "protected". Subclasses are // allowed to use it when making protected resource requests to retrieve // the user profile. this._oauth2 = new OAuth2(options.clientID, options.clientSecret, '', options.authorizationURL, options.tokenURL, options.customHeaders); this._callbackURL = options.callbackURL; this._scope = options.scope; this._scopeSeparator = options.scopeSeparator || ' '; this._key = options.sessionKey || ('oauth2:' + url.parse(options.authorizationURL).hostname); if (options.store) { this._stateStore = options.store; } else { if (options.state) { this._stateStore = new SessionStateStore({ key: this._key }); } else { this._stateStore = new NullStateStore(); } } this._trustProxy = options.proxy; this._passReqToCallback = options.passReqToCallback; this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile; }
n/a
function InternalOAuthError(message, err) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.oauthError = err; }
n/a
function Strategy() { }
n/a
function OAuthStrategy(options, verify) { if (typeof options == 'function') { verify = options; options = undefined; } options = options || {}; if (!verify) { throw new TypeError('OAuthStrategy requires a verify callback'); } if (!options.requestTokenURL) { throw new TypeError('OAuthStrategy requires a requestTokenURL option'); } if (!options.accessTokenURL) { throw new TypeError('OAuthStrategy requires a accessTokenURL option'); } if (!options.userAuthorizationURL) { throw new TypeError('OAuthStrategy requires a userAuthorizationURL option'); } if (!options.consumerKey) { throw new TypeError('OAuthStrategy requires a consumerKey option'); } if (options.consumerSecret === undefined) { throw new TypeError('OAuthStrategy requires a consumerSecret option'); } passport.Strategy.call(this); this.name = 'oauth'; this._verify = verify; // NOTE: The _oauth property is considered "protected". Subclasses are // allowed to use it when making protected resource requests to retrieve // the user profile. this._oauth = new OAuth(options.requestTokenURL, options.accessTokenURL, options.consumerKey, options.consumerSecret, '1.0', null, options.signatureMethod || 'HMAC-SHA1', null, options.customHeaders); this._userAuthorizationURL = options.userAuthorizationURL; this._callbackURL = options.callbackURL; this._key = options.sessionKey || 'oauth'; this._requestTokenStore = options.requestTokenStore || new SessionRequestTokenStore({ key: this._key }); this._trustProxy = options.proxy; this._passReqToCallback = options.passReqToCallback; this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile; }
n/a
function InternalOAuthError(message, err) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.oauthError = err; }
n/a
toString = function () { var m = this.name; if (this.message) { m += ': ' + this.message; } if (this.oauthError) { if (this.oauthError instanceof Error) { m = this.oauthError.toString(); } else if (this.oauthError.statusCode && this.oauthError.data) { m += ' (status: ' + this.oauthError.statusCode + ' data: ' + this.oauthError.data + ')'; } } return m; }
n/a
function OAuth2Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = undefined; } options = options || {}; if (!verify) { throw new TypeError('OAuth2Strategy requires a verify callback'); } if (!options.authorizationURL) { throw new TypeError('OAuth2Strategy requires a authorizationURL option'); } if (!options.tokenURL) { throw new TypeError('OAuth2Strategy requires a tokenURL option'); } if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); } passport.Strategy.call(this); this.name = 'oauth2'; this._verify = verify; // NOTE: The _oauth2 property is considered "protected". Subclasses are // allowed to use it when making protected resource requests to retrieve // the user profile. this._oauth2 = new OAuth2(options.clientID, options.clientSecret, '', options.authorizationURL, options.tokenURL, options.customHeaders); this._callbackURL = options.callbackURL; this._scope = options.scope; this._scopeSeparator = options.scopeSeparator || ' '; this._key = options.sessionKey || ('oauth2:' + url.parse(options.authorizationURL).hostname); if (options.store) { this._stateStore = options.store; } else { if (options.state) { this._stateStore = new SessionStateStore({ key: this._key }); } else { this._stateStore = new NullStateStore(); } } this._trustProxy = options.proxy; this._passReqToCallback = options.passReqToCallback; this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile; }
n/a
function AuthorizationError(message, code, uri, status) { if (!status) { switch (code) { case 'access_denied': status = 403; break; case 'server_error': status = 502; break; case 'temporarily_unavailable': status = 503; break; } } Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.code = code || 'server_error'; this.uri = uri; this.status = status || 500; }
n/a
function InternalOAuthError(message, err) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.oauthError = err; }
n/a
function OAuth2Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = undefined; } options = options || {}; if (!verify) { throw new TypeError('OAuth2Strategy requires a verify callback'); } if (!options.authorizationURL) { throw new TypeError('OAuth2Strategy requires a authorizationURL option'); } if (!options.tokenURL) { throw new TypeError('OAuth2Strategy requires a tokenURL option'); } if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); } passport.Strategy.call(this); this.name = 'oauth2'; this._verify = verify; // NOTE: The _oauth2 property is considered "protected". Subclasses are // allowed to use it when making protected resource requests to retrieve // the user profile. this._oauth2 = new OAuth2(options.clientID, options.clientSecret, '', options.authorizationURL, options.tokenURL, options.customHeaders); this._callbackURL = options.callbackURL; this._scope = options.scope; this._scopeSeparator = options.scopeSeparator || ' '; this._key = options.sessionKey || ('oauth2:' + url.parse(options.authorizationURL).hostname); if (options.store) { this._stateStore = options.store; } else { if (options.state) { this._stateStore = new SessionStateStore({ key: this._key }); } else { this._stateStore = new NullStateStore(); } } this._trustProxy = options.proxy; this._passReqToCallback = options.passReqToCallback; this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile; }
n/a
function TokenError(message, code, uri, status) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.code = code || 'invalid_request'; this.uri = uri; this.status = status || 500; }
n/a
function Strategy() { }
n/a
function InternalOAuthError(message, err) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.oauthError = err; }
n/a
toString = function () { var m = this.name; if (this.message) { m += ': ' + this.message; } if (this.oauthError) { if (this.oauthError instanceof Error) { m = this.oauthError.toString(); } else if (this.oauthError.statusCode && this.oauthError.data) { m += ' (status: ' + this.oauthError.statusCode + ' data: ' + this.oauthError.data + ')'; } } return m; }
n/a
_createOAuthError = function (message, err) { var e; if (err.statusCode && err.data) { try { e = this.parseErrorResponse(err.data, err.statusCode); } catch (_) {} } if (!e) { e = new InternalOAuthError(message, err); } return e; }
n/a
_loadUserProfile = function (accessToken, done) { var self = this; function loadIt() { return self.userProfile(accessToken, done); } function skipIt() { return done(null); } if (typeof this._skipUserProfile == 'function' && this._skipUserProfile.length > 1) { // async this._skipUserProfile(accessToken, function(err, skip) { if (err) { return done(err); } if (!skip) { return loadIt(); } return skipIt(); }); } else { var skip = (typeof this._skipUserProfile == 'function') ? this._skipUserProfile() : this._skipUserProfile; if (!skip) { return loadIt(); } return skipIt(); } }
n/a
authenticate = function (req, options) { options = options || {}; var self = this; if (req.query && req.query.error) { if (req.query.error == 'access_denied') { return this.fail({ message: req.query.error_description }); } else { return this.error(new AuthorizationError(req.query.error_description, req.query.error, req.query.error_uri)); } } var callbackURL = options.callbackURL || this._callbackURL; if (callbackURL) { var parsed = url.parse(callbackURL); if (!parsed.protocol) { // The callback URL is relative, resolve a fully qualified URL from the // URL of the originating request. callbackURL = url.resolve(utils.originalURL(req, { proxy: this._trustProxy }), callbackURL); } } var meta = { authorizationURL: this._oauth2._authorizeUrl, tokenURL: this._oauth2._accessTokenUrl, clientID: this._oauth2._clientId } if (req.query && req.query.code) { function loaded(err, ok, state) { if (err) { return self.error(err); } if (!ok) { return self.fail(state, 403); } var code = req.query.code; var params = self.tokenParams(options); params.grant_type = 'authorization_code'; if (callbackURL) { params.redirect_uri = callbackURL; } self._oauth2.getOAuthAccessToken(code, params, function(err, accessToken, refreshToken, params) { if (err) { return self.error(self._createOAuthError('Failed to obtain access token', err)); } self._loadUserProfile(accessToken, function(err, profile) { if (err) { return self.error(err); } function verified(err, user, info) { if (err) { return self.error(err); } if (!user) { return self.fail(info); } info = info || {}; if (state) { info.state = state; } self.success(user, info); } try { if (self._passReqToCallback) { var arity = self._verify.length; if (arity == 6) { self._verify(req, accessToken, refreshToken, params, profile, verified); } else { // arity == 5 self._verify(req, accessToken, refreshToken, profile, verified); } } else { var arity = self._verify.length; if (arity == 5) { self._verify(accessToken, refreshToken, params, profile, verified); } else { // arity == 4 self._verify(accessToken, refreshToken, profile, verified); } } } catch (ex) { return self.error(ex); } }); } ); } var state = req.query.state; try { var arity = this._stateStore.verify.length; if (arity == 4) { this._stateStore.verify(req, state, meta, loaded); } else { // arity == 3 this._stateStore.verify(req, state, loaded); } } catch (ex) { return this.error(ex); } } else { var params = this.authorizationParams(options); params.response_type = 'code'; if (callbackURL) { params.redirect_uri = callbackURL; } var scope = options.scope || this._scope; if (scope) { if (Array.isArray(scope)) { scope = scope.join(this._scopeSeparator); } params.scope = scope; } var state = options.state; if (state) { params.state = state; var parsed = url.parse(this._oauth2._authorizeUrl, true); utils.merge(parsed.query, params); parsed.query['client_id'] = this._oauth2._clientId; delete parsed.search; var location = url.format(parsed); this.redirect(location); } else { function stored(err, state) { if (err) { return self.error(err); } if (state) { params.state = state; } var parsed = url.parse(self._oauth2._authorizeUrl, true); utils.merge(parsed.query, params); parsed.query['client_id'] = self._oauth2._clientId; delete parsed.search; ...
n/a
authorizationParams = function (options) { return {}; }
n/a
parseErrorResponse = function (body, status) { var json = JSON.parse(body); if (json.error) { return new TokenError(json.error_description, json.error, json.error_uri); } return null; }
n/a
tokenParams = function (options) { return {}; }
n/a
userProfile = function (accessToken, done) { return done(null, {}); }
n/a
function Strategy() { }
n/a
function Strategy() { }
n/a
authenticate = function (req, options) { throw new Error('Strategy#authenticate must be overridden by subclass'); }
n/a
function OAuthStrategy(options, verify) { if (typeof options == 'function') { verify = options; options = undefined; } options = options || {}; if (!verify) { throw new TypeError('OAuthStrategy requires a verify callback'); } if (!options.requestTokenURL) { throw new TypeError('OAuthStrategy requires a requestTokenURL option'); } if (!options.accessTokenURL) { throw new TypeError('OAuthStrategy requires a accessTokenURL option'); } if (!options.userAuthorizationURL) { throw new TypeError('OAuthStrategy requires a userAuthorizationURL option'); } if (!options.consumerKey) { throw new TypeError('OAuthStrategy requires a consumerKey option'); } if (options.consumerSecret === undefined) { throw new TypeError('OAuthStrategy requires a consumerSecret option'); } passport.Strategy.call(this); this.name = 'oauth'; this._verify = verify; // NOTE: The _oauth property is considered "protected". Subclasses are // allowed to use it when making protected resource requests to retrieve // the user profile. this._oauth = new OAuth(options.requestTokenURL, options.accessTokenURL, options.consumerKey, options.consumerSecret, '1.0', null, options.signatureMethod || 'HMAC-SHA1', null, options.customHeaders); this._userAuthorizationURL = options.userAuthorizationURL; this._callbackURL = options.callbackURL; this._key = options.sessionKey || 'oauth'; this._requestTokenStore = options.requestTokenStore || new SessionRequestTokenStore({ key: this._key }); this._trustProxy = options.proxy; this._passReqToCallback = options.passReqToCallback; this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile; }
n/a
function InternalOAuthError(message, err) { Error.call(this); Error.captureStackTrace(this, this.constructor); this.name = this.constructor.name; this.message = message; this.oauthError = err; }
n/a
function OAuthStrategy(options, verify) { if (typeof options == 'function') { verify = options; options = undefined; } options = options || {}; if (!verify) { throw new TypeError('OAuthStrategy requires a verify callback'); } if (!options.requestTokenURL) { throw new TypeError('OAuthStrategy requires a requestTokenURL option'); } if (!options.accessTokenURL) { throw new TypeError('OAuthStrategy requires a accessTokenURL option'); } if (!options.userAuthorizationURL) { throw new TypeError('OAuthStrategy requires a userAuthorizationURL option'); } if (!options.consumerKey) { throw new TypeError('OAuthStrategy requires a consumerKey option'); } if (options.consumerSecret === undefined) { throw new TypeError('OAuthStrategy requires a consumerSecret option'); } passport.Strategy.call(this); this.name = 'oauth'; this._verify = verify; // NOTE: The _oauth property is considered "protected". Subclasses are // allowed to use it when making protected resource requests to retrieve // the user profile. this._oauth = new OAuth(options.requestTokenURL, options.accessTokenURL, options.consumerKey, options.consumerSecret, '1.0', null, options.signatureMethod || 'HMAC-SHA1', null, options.customHeaders); this._userAuthorizationURL = options.userAuthorizationURL; this._callbackURL = options.callbackURL; this._key = options.sessionKey || 'oauth'; this._requestTokenStore = options.requestTokenStore || new SessionRequestTokenStore({ key: this._key }); this._trustProxy = options.proxy; this._passReqToCallback = options.passReqToCallback; this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile; }
n/a
function Strategy() { }
n/a
_createOAuthError = function (message, err) { var e; if (err.statusCode && err.data) { try { e = this.parseErrorResponse(err.data, err.statusCode); } catch (_) {} } if (!e) { e = new InternalOAuthError(message, err); } return e; }
n/a
_loadUserProfile = function (token, tokenSecret, params, done) { var self = this; function loadIt() { return self.userProfile(token, tokenSecret, params, done); } function skipIt() { return done(null); } if (typeof this._skipUserProfile == 'function' && this._skipUserProfile.length > 1) { // async this._skipUserProfile(token, tokenSecret, function(err, skip) { if (err) { return done(err); } if (!skip) { return loadIt(); } return skipIt(); }); } else { var skip = (typeof this._skipUserProfile == 'function') ? this._skipUserProfile() : this._skipUserProfile; if (!skip) { return loadIt(); } return skipIt(); } }
n/a
authenticate = function (req, options) { options = options || {}; var self = this; var meta = { requestTokenURL: this._oauth._requestUrl, accessTokenURL: this._oauth._accessUrl, userAuthorizationURL: this._userAuthorizationURL, consumerKey: this._oauth._consumerKey } if (req.query && req.query.oauth_token) { // The request being authenticated contains an oauth_token parameter in the // query portion of the URL. This indicates that the service provider has // redirected the user back to the application, after authenticating the // user and obtaining their authorization. // // The value of the oauth_token parameter is the request token. Together // with knowledge of the token secret (stored in the session), the request // token can be exchanged for an access token and token secret. // // This access token and token secret, along with the optional ability to // fetch profile information from the service provider, is sufficient to // establish the identity of the user. var oauthToken = req.query.oauth_token; function loaded(err, oauthTokenSecret, state) { if (err) { return self.error(err); } if (!oauthTokenSecret) { return self.fail(state, 403); } // NOTE: The oauth_verifier parameter will be supplied in the query portion // of the redirect URL, if the server supports OAuth 1.0a. var oauthVerifier = req.query.oauth_verifier || null; self._oauth.getOAuthAccessToken(oauthToken, oauthTokenSecret, oauthVerifier, function(err, token, tokenSecret, params) { if (err) { return self.error(self._createOAuthError('Failed to obtain access token', err)); } function destroyed(err) { if (err) { return self.error(err); } self._loadUserProfile(token, tokenSecret, params, function(err, profile) { if (err) { return self.error(err); } function verified(err, user, info) { if (err) { return self.error(err); } if (!user) { return self.fail(info); } info = info || {}; if (state) { info.state = state; } self.success(user, info); } try { if (self._passReqToCallback) { var arity = self._verify.length; if (arity == 6) { self._verify(req, token, tokenSecret, params, profile, verified); } else { // arity == 5 self._verify(req, token, tokenSecret, profile, verified); } } else { var arity = self._verify.length; if (arity == 5) { self._verify(token, tokenSecret, params, profile, verified); } else { // arity == 4 self._verify(token, tokenSecret, profile, verified); } } } catch (ex) { return self.error(ex); } }); } // The request token has been exchanged for an access token. Since the // request token is a single-use token, that data can be removed from the // store. try { var arity = self._requestTokenStore.destroy.length; if (arity == 4) { self._requestTokenStore.destroy(req, oauthToken, meta, destroyed); } else { // arity == 3 self._requestTokenStore.destroy(req, oauthToken, destroyed); } } catch (ex) { return self.error(ex); } }); } try { var arity = self._requestTokenStore.get.length; if (arity == 4) { this._requestTokenStore.get(req, oauthToken, meta, loaded); } else { // arity == 3 this._requestTokenStore.get(req, oauthToken, loaded); } } catch (ex) { return this.error(ex); } } else { // In order to authenticate via OAuth, the application must obtain a request // token from the service provider and redirect th ...
n/a
parseErrorResponse = function (body, status) { return null; }
n/a
requestTokenParams = function (options) { return {}; }
n/a
userAuthorizationParams = function (options) { return {}; }
n/a
userProfile = function (token, tokenSecret, params, done) { return done(null, {}); }
n/a