How to use the passport-http.BasicStrategy function in passport-http

To help you get started, we’ve selected a few passport-http 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 strongloop / loopback-next / labs / authentication-passport / src / __tests__ / acceptance / authentication-with-passport-strategy-adapter.acceptance.ts View on Github external
Flinstone: {profile: {id: 'Flint'}, password: 'beta'},
      George: {profile: {id: 'Curious'}, password: 'gamma'},
    });
  }

  // Since it has to be user's job to provide the `verify` function and
  // instantiate the passport strategy, we cannot add the imported `BasicStrategy`
  // class as extension directly.
  // We need to either wrap it as a strategy provider, and add the provider
  // class as the extension. (When having something like the verify function to inject)
  // Or just wrap the basic strategy instance and bind it to the app. (When nothing to inject)

  function verify(username: string, password: string, cb: Function) {
    users.find(username, password, cb);
  }
  const basicStrategy = new BasicStrategy(verify);
  const basicAuthStrategy = new StrategyAdapter(
    basicStrategy,
    AUTH_STRATEGY_NAME,
  );

  async function givenAServer() {
    app = new Application();
    app.component(AuthenticationComponent);
    app.component(RestComponent);
    app
      .bind('authentication.strategies.basicAuthStrategy')
      .to(basicAuthStrategy)
      .tag({
        [CoreTags.EXTENSION_FOR]:
          AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
      });
github raineroviir / react-redux-socketio-chat / lib / passport_strategy.js View on Github external
module.exports = function passportStrategy(passport) {
  passport.use('basic', new BasicStrategy({}, function(email, password, done) { // Auth email/pass sent in header
    User.findOne({'email': email}, function(err, user) {
      if (err) return done('database error');
      if (!user) return done('user not found');
      user.checkPassword(password, function(err, result) {
        if (err) console.log(err);
        if (!result) return done('wrong password');
        // return user if no auth errors
        return done(null, user);
      });
    });
  }));
};
github weseek / growi / src / server / service / passport.js View on Github external
// check whether the strategy has already been set up
    if (this.isBasicStrategySetup) {
      throw new Error('BasicStrategy has already been set up');
    }

    const configManager = this.crowi.configManager;
    const isBasicEnabled = configManager.getConfig('crowi', 'security:passport-basic:isEnabled');

    // when disabled
    if (!isBasicEnabled) {
      return;
    }

    debug('BasicStrategy: setting up..');

    passport.use(new BasicStrategy(
      (userId, password, done) => {
        if (userId != null) {
          return done(null, userId);
        }
        return done(null, false, { message: 'Incorrect credentials.' });
      },
    ));

    this.isBasicStrategySetup = true;
    debug('BasicStrategy: setup is done');
  }
github wisnuc / appifi / src / middleware / Auth.js View on Github external
return Array.isArray(value) ? value : []
      }
    })

    // this.users = users
    this.secret = secret

    let jwtOpts = {
      secretOrKey: this.secret,
      jwtFromRequest: ExtractJwt.fromAuthHeaderWithScheme('jwt')
    }

    // this is not officially documented
    // see https://github.com/jaredhanson/passport/issues/27
    this.pp = new passport.Passport()
    this.pp.use(new BasicStrategy(this.handleBasicAuth.bind(this)))
    this.pp.use(new JwtStrategy(jwtOpts, this.handleJwtAuth.bind(this)))
    this.middleware = this.pp.initialize()
  }
github CrucifixArnaud / rapworldmap / app / config / passport.js View on Github external
// if no user is found, return the message
      if (!user)
        return done(null, false, { message: 'No user with this email.' });

      // if the user is found but password invalid
      if (!user.validPassword(password))
        return done(null, false, { message: 'Invalid email or password.' });

      return done(null, user);
    });

  }));

  //====== Basic Auth ======
  passport.use('basic', new BasicStrategy(function(email, password, done) {
    User.findOne({ email: email }, function (err, user) {
      if (err)
        return done(err);

      // if no user is found, return the message
      if (!user)
        return done(null, false);

      // if the user is found but password invalid
      if (!user.validPassword(password))
        return done(null, false);

      return done(null, user);
    });
  }));
github Aionic-Apps / aionic-core / src / api / components / global / auth / strategies / basicAuth.ts View on Github external
public constructor() {
		super();
		this._strategy = new BasicStrategy(this.verify);
	}
github TreeGateway / tree-gateway / bin / lib / authentication / strategies / basic.js View on Github external
module.exports = function (apiKey, authConfig, gateway) {
    var p = pathUtil.join(gateway.middlewarePath, 'authentication', 'verify', authConfig.verify);
    var verifyFunction = require(p);
    passport.use(apiKey, new passport_http_1.BasicStrategy(verifyFunction));
};
github TreeGateway / tree-gateway / src / lib / authentication / strategies / basic.ts View on Github external
module.exports = function (authConfig: BasicAuthentication, config: Configuration) {
    let p = pathUtil.join(config.middlewarePath, 'authentication', 'verify', authConfig.verify);                
    let verifyFunction = require(p);
    return new BasicStrategy(verifyFunction);
};
github vbauer / manet / src / filters.js View on Github external
function configureWebSecurity(conf) {
    const creds = getBasic(conf);
    if (creds) {
        passport.use(new passportHttp.BasicStrategy((username, password, done) => {
            const name = creds.username,
                  passwd = creds.password,
                  correct = name === username && passwd === password;
            done(null, correct ? basic : false);
        }));
    }
}

passport-http

HTTP Basic and Digest authentication strategies for Passport.

MIT
Latest version published 9 years ago

Package Health Score

56 / 100
Full package analysis

Popular passport-http functions