Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// (2) common endpoint is not supported
//---------------------------------------------------------------------------
// for B2C,
if (options.isB2C) {
if (!options.policyName || !CONSTANTS.POLICY_REGEX.test(options.policyName))
throw new Error('In BearerStrategy constructor: invalid policy for B2C');
}
// if logging level specified, switch to it.
if (options.loggingLevel) { log.levels('console', options.loggingLevel); }
log.info(`In BearerStrategy constructor: created strategy with options ${JSON.stringify(options)}`);
}
util.inherits(Strategy, passport.Strategy);
Strategy.prototype.jwtVerify = function jwtVerifyFunc(req, token, metadata, optionsToValidate, done) {
const self = this;
const decoded = jws.decode(token);
let PEMkey = null;
if (decoded == null) {
return done(null, false, 'In Strategy.prototype.jwtVerify: Invalid JWT token.');
}
log.info('In Strategy.prototype.jwtVerify: token decoded: ', decoded);
// When we generate the PEMkey, there are two different types of token signatures
// we have to validate here. One provides x5t and the other a kid. We need to call
// the right one.
function Strategy(options, verify) {
passport.Strategy.call(this);
/*
* Caution when you want to change these values in the member functions of
* Strategy, don't use `this`, since `this` points to a subclass of `Strategy`.
* To get `Strategy`, use Object.getPrototypeOf(this).
*
* More comments at the beginning of `Strategy.prototype.authenticate`.
*/
this._options = options;
this.name = 'azuread-openidconnect';
// stuff related to the verify function
this._verify = verify;
this._passReqToCallback = !!options.passReqToCallback;
if (options.useCookieInsteadOfSession === true)
// 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._passReqToCallback = options.passReqToCallback;
this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile;
}
/**
* Inherit from `passport.Strategy`.
*/
util.inherits(OAuth2Strategy, passport.Strategy);
/**
* Authenticate request by delegating to a service provider using OAuth 2.0.
*
* @param {Object} req
* @api protected
*/
OAuth2Strategy.prototype.authenticate = function(req, options) {
options = options || {};
var self = this;
if (req.query && req.query.error) {
// TODO: Error information pertaining to OAuth 2.0 flows is encoded in the
// query parameters, and should be propagated to the application.
return this.fail();
}
this.metadata = null;
this.identityProviderUrl = opts.identityProviderUrl;
this.certs.push(opts.cert);
}
opts.metadata = this.metadata;
this._verify = verify;
this._saml = new saml.SAML(opts);
this._wsfed = new WSFed(opts);
this._passReqToCallback = !!opts.passReqToCallback;
}
util.inherits(Strategy, passport.Strategy);
Strategy.prototype.authenticate = function authenticate(req) {
const self = this;
let wsfed;
if (this.metadata && !this.metadata.wsfed) {
this.metadata.fetch((fetchMetadataError) => {
if (fetchMetadataError) {
return self.error(fetchMetadataError);
}
wsfed = self.metadata.wsfed;
self._saml.certs = wsfed.certs;
self._wsfed.identityProviderUrl = wsfed.loginEndpoint;
return self._doAuthenticate(req);
});
} else {
function AnonymousStrategy() {
passport.Strategy.call(this);
this.name = 'anon';
}
util.inherits(AnonymousStrategy, passport.Strategy);
function Strategy (options, verify) {
if (typeof options === 'function') {
verify = options;
options = {};
}
if (!verify) throw new Error('local authentication strategy requires a verify function');
this._apiKeyField = options.apiKeyField;
this._apiKeyHeader = options.apiKeyHeader;
this._apiKeyHeaderScheme = options.apiKeyHeaderScheme;
passport.Strategy.call(this);
this.name = 'localapikey';
this._verify = verify;
this._passReqToCallback = options.passReqToCallback;
}
function Strategy(options, verify) {
if (typeof options === 'function') {
verify = options;
options = {};
}
if (!verify) {
throw new Error('Token strategy requires a verify function');
}
this._tokenHeader = options.tokenHeader || 'token';
passport.Strategy.call(this);
this.name = 'token';
this._verify = verify;
this._passReqToCallback = options.passReqToCallback;
}
const Strategy = function() {
passport.Strategy.call(this);
this.name = 'signed';
};
function AnonymousStrategy() {
passport.Strategy.call(this);
this.name = 'anon';
}
util.inherits(AnonymousStrategy, passport.Strategy);
const Strategy = function(options, verify) {
this.name = 'shibboleth';
this.options = options;
this.verify = verify;
this._passReqToCallback = options.passReqToCallback;
passport.Strategy.call(this);
};