How to use passport-strategy - 10 common examples

To help you get started, we’ve selected a few passport-strategy 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 kndt84 / passport-cognito / lib / strategy.js View on Github external
if (!options) throw new Error('Cognito strategy requires options');
  if (!verify) throw new Error('Cognito strategy requires a verify callback');

  AWS.config.region = options.region;

  passport.Strategy.call(this);
  this.name = 'cognito';
  this._userPoolId = options.userPoolId;
  this._clientId = options.clientId;
  this._verify = verify;
}


// Inherit from `passport-strategy`.
util.inherits(CognitoStrategy, passport.Strategy);


/**
 * Authenticate request
 *
 * @param {http.IncomingMessage} req
 * @param {object} options
 * @access protected
 */
CognitoStrategy.prototype.authenticate = function(req, options) {

  var user = {};
  var username = req.body.username;
  var password = req.body.password;

  if (!username || !password) {
github feathersjs-ecosystem / authentication / test / fixtures / strategy.js View on Github external
const Strategy = function (options, verify) {
  passport.Strategy.call(this);
  this.name = 'mock';
  this._options = options;
  this._verify = verify;
};
github eddywashere / passport-keystone / lib / passport-keystone / strategy.js View on Github external
this._usernameField = options.usernameField || 'username';
  this._passwordField = options.passwordField || 'password';
  this._region = options.region || '';
  this._authUrl = options.authUrl || '';
  this._tenantId = options.tenantId || '';

  passport.Strategy.call(this);
  this.name = 'keystone';
  this._verify = verify;
  this._passReqToCallback = options.passReqToCallback;
}

/**
 * Inherit from `passport.Strategy`.
 */
util.inherits(Strategy, passport.Strategy);

/**
 * Get value for given field from given object. Taken from passport-local,
 * copyright 2011-2013 Jared Hanson
 */
var lookup = function (obj, field) {
  var i, len, chain, prop;
  if (!obj) { return null; }
  chain = field.split(']').join('').split('[');
  for (i = 0, len = chain.length; i < len; i++) {
    prop = obj[chain[i]];
    if (typeof(prop) === 'undefined') { return null; }
    if (typeof(prop) !== 'object') { return prop; }
    obj = prop;
  }
  return null;
github jaredhanson / passport-http-bearer / lib / strategy.js View on Github external
if (!verify) { throw new TypeError('HTTPBearerStrategy requires a verify callback'); }
  
  passport.Strategy.call(this);
  this.name = 'bearer';
  this._verify = verify;
  this._realm = options.realm || 'Users';
  if (options.scope) {
    this._scope = (Array.isArray(options.scope)) ? options.scope : [ options.scope ];
  }
  this._passReqToCallback = options.passReqToCallback;
}

/**
 * Inherit from `passport.Strategy`.
 */
util.inherits(Strategy, passport.Strategy);

/**
 * Authenticate request based on the contents of a HTTP Bearer authorization
 * header, body parameter, or query parameter.
 *
 * @param {Object} req
 * @api protected
 */
Strategy.prototype.authenticate = function(req) {
  var token;
  
  if (req.headers && req.headers.authorization) {
    var parts = req.headers.authorization.split(' ');
    if (parts.length == 2) {
      var scheme = parts[0]
        , credentials = parts[1];
github jaredhanson / passport-http-bearer / lib / strategy.js View on Github external
function Strategy(options, verify) {
  if (typeof options == 'function') {
    verify = options;
    options = {};
  }
  if (!verify) { throw new TypeError('HTTPBearerStrategy requires a verify callback'); }
  
  passport.Strategy.call(this);
  this.name = 'bearer';
  this._verify = verify;
  this._realm = options.realm || 'Users';
  if (options.scope) {
    this._scope = (Array.isArray(options.scope)) ? options.scope : [ options.scope ];
  }
  this._passReqToCallback = options.passReqToCallback;
}
github ilich / passport-2fa-totp / lib / strategy.js View on Github external
}
    
    if (!verifyUsernameAndPassword) {
        throw new TypeError('2FA TOTP Strategy required username and password verification callback');
    }
    
    if (!this._skipTotpVerification && !verifyTotpCode) {
        throw new TypeError('2FA TOTP Strategy required TOTP code verification callback');
    }
    
    this._usernameField = options.usernameField || 'username';
    this._passwordField = options.passwordField || 'password';
    this._codeField = options.codeField || 'code';
    this._window = options.window || 6;

    passport.Strategy.call(this);
    
    this.name = '2fa-totp';
    this._verifyUsernameAndPassword = verifyUsernameAndPassword;
    this._verifyTotpCode = verifyTotpCode;
    this._passReqToCallback = options.passReqToCallback || false;
}
github didinj / node-express-mongoose-passport-jwt-rest-api-auth / node_modules / passport-jwt / lib / strategy.js View on Github external
}

    this._passReqToCallback = options.passReqToCallback;
    var jsonWebTokenOptions = options.jsonWebTokenOptions || {};
    //for backwards compatibility, still allowing you to pass
    //audience / issuer / algorithms / ignoreExpiration
    //on the options.
    this._verifOpts = assign({}, jsonWebTokenOptions, {
      audience: options.audience,
      issuer: options.issuer,
      algorithms: options.algorithms,
      ignoreExpiration: !!options.ignoreExpiration
    });

}
util.inherits(JwtStrategy, passport.Strategy);



/**
 * Allow for injection of JWT Verifier.
 *
 * This improves testability by allowing tests to cleanly isolate failures in the JWT Verification
 * process from failures in the passport related mechanics of authentication.
 *
 * Note that this should only be replaced in tests.
 */
JwtStrategy.JwtVerifier = require('./verify_jwt');



/**
github vulcainjs / vulcain-corejs / src / auth / bearerStrategy.ts View on Github external
import * as passportStrategy from 'passport-strategy';

export class BearerStrategy extends passportStrategy.Strategy {

    name: string;
    private _verify: Function;

  constructor(verify: Function)
  {
        if (!verify) {
            throw new TypeError('BearerStrategy requires a verify callback');
        }

        super();

        this.name = 'bearer';
        this._verify = verify;
    }
github onehilltech / blueprint / packages / blueprint-gatekeeper / src / server / lib / authentication / client.js View on Github external
function ClientStrategy (options, verify) {
  if (typeof options == 'function') {
    verify = options;
    options = {};
  }
  if (!verify)
    throw new Error('OAuth 2.0 client strategy requires a verify function');

  passport.Strategy.call (this);
  this.name = 'oauth2-client';
  this._verify = verify;
  this._passReqToCallback = options.passReqToCallback;
}
github vcwen / passport-wechat-enterprise / lib / strategy.js View on Github external
passport.Strategy.call(this)
  this.name = 'wechat-enterprise'
  this._verify = verify
  this._oauth = new OAuth2(options.corpId, options.corpSecret, _getAccessToken, _saveAccessToken)
  this._callbackURL = options.callbackURL
  this._scope = options.scope
  this._scopeSeparator = options.scopeSeparator || ' '
  this._state = options.state
  this._passReqToCallback = options.passReqToCallback
}

/**
 * Inherit from `passport.Strategy`.
 */
util.inherits(WechatEnterpriseStrategy, passport.Strategy)


/**
 * Authenticate request by delegating to a service provider using OAuth 2.0.
 *
 * @param {Object} req
 * @api protected
 */
WechatEnterpriseStrategy.prototype.authenticate = function(req, options) {
  options = options || {}

  var self = this
  var callbackURL = options.callbackURL || this._callbackURL
  if (callbackURL) {
    var parsed = url.parse(callbackURL)
    if (!parsed.protocol) {

passport-strategy

An abstract class implementing Passport's strategy API.

MIT
Latest version published 11 years ago

Package Health Score

67 / 100
Full package analysis