How to use the passport.Strategy function in passport

To help you get started, we’ve selected a few passport examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AzureAD / passport-azure-ad / lib / bearerstrategy.js View on Github external
// (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.
github AzureAD / passport-azure-ad / lib / oidcstrategy.js View on Github external
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)
github florianheinemann / passport-dropbox-oauth2 / modules / passport-oauth / lib / passport-oauth / strategies / oauth2.js View on Github external
//       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();
github AzureAD / passport-azure-ad / lib / passport-azure-ad / wsfedstrategy.js View on Github external
}

    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 {
github node-red / node-red / red / api / auth / strategies.js View on Github external
function AnonymousStrategy() {
  passport.Strategy.call(this);
  this.name = 'anon';
}
util.inherits(AnonymousStrategy, passport.Strategy);
github ExpressGateway / express-gateway / lib / policies / key-auth / passport-apikey-strategy.js View on Github external
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;
}
github amida-tech / greyscale / backend / lib / passport_token.js View on Github external
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;
}
github oaeproject / Hilary / packages / oae-authentication / lib / strategies / signed / strategy.js View on Github external
const Strategy = function() {
  passport.Strategy.call(this);
  this.name = 'signed';
};
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / auth / strategies.js View on Github external
function AnonymousStrategy() {
  passport.Strategy.call(this);
  this.name = 'anon';
}
util.inherits(AnonymousStrategy, passport.Strategy);
github oaeproject / Hilary / packages / oae-authentication / lib / strategies / shibboleth / strategy.js View on Github external
const Strategy = function(options, verify) {
  this.name = 'shibboleth';
  this.options = options;
  this.verify = verify;
  this._passReqToCallback = options.passReqToCallback;
  passport.Strategy.call(this);
};