How to use the @feathersjs/authentication.express function in @feathersjs/authentication

To help you get started, we’ve selected a few @feathersjs/authentication 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 feathersjs / feathers / packages / authentication-oauth2 / lib / index.js View on Github external
const Verifier = options.Verifier || DefaultVerifier;
    const formatter = options.formatter || rest.formatter;
    const handler = options.handler || defaultHandler(oauth2Settings);
    const errorHandler = typeof options.errorHandler === 'function' ? options.errorHandler(oauth2Settings) : defaultErrorHandler(oauth2Settings);

    // register OAuth middleware
    debug(`Registering '${name}' Express OAuth middleware`);
    app.get(oauth2Settings.path, auth.express.authenticate(name, omit(oauth2Settings, 'state')));
    app.get(
      oauth2Settings.callbackPath,
      _callbackAuthenticator(authSettings),
      auth.express.authenticate(name, omit(oauth2Settings, 'state')),
      handler,
      errorHandler,
      auth.express.emitEvents(authSettings, app),
      auth.express.setCookie(authSettings),
      auth.express.successRedirect(),
      auth.express.failureRedirect(authSettings),
      formatter
    );

    app.setup = function () {
      let result = _super.apply(this, arguments);
      let verifier = new Verifier(app, oauth2Settings);

      if (!verifier.verify) {
        throw new Error(`Your verifier must implement a 'verify' function. It should have the same signature as a oauth2 passport verify callback.`);
      }

      // Register 'oauth2' strategy with passport
      debug('Registering oauth2 authentication strategy with options:', oauth2Settings);
github feathersjs / feathers / packages / authentication-oauth2 / lib / index.js View on Github external
return function (req, res, next) {
    auth.express.authenticate('jwt', config)(req, res, () => {
      // We have to mark this as unauthenticated even though req.user may be set
      // because we still need the OAuth strategy to run in next()
      req.authenticated = false;
      next();
    });
  };
}
github feathersjs / feathers / packages / authentication-oauth1 / lib / index.js View on Github external
const errorHandler = defaultErrorHandler(oauth1Settings);

    // register OAuth middleware
    debug(`Registering '${name}' Express OAuth middleware`);
    app.get(oauth1Settings.path, auth.express.authenticate(name, oauth1Settings));
    app.get(
      oauth1Settings.callbackPath,
      // NOTE (EK): We register failure redirect here so that we can
      // retain the natural express middleware redirect ability like
      // you would have with vanilla passport.
      auth.express.authenticate(name, oauth1Settings),
      handler,
      errorHandler,
      auth.express.emitEvents(authSettings, app),
      auth.express.setCookie(authSettings),
      auth.express.successRedirect(),
      auth.express.failureRedirect(authSettings),
      formatter
    );

    app.setup = function () {
      let result = _super.apply(this, arguments);
      let verifier = new Verifier(app, oauth1Settings);

      if (!verifier.verify) {
        throw new Error(`Your verifier must implement a 'verify' function. It should have the same signature as a oauth1 passport verify callback.`);
      }

      // Register 'oauth1' strategy with passport
      debug('Registering oauth1 authentication strategy with options:', oauth1Settings);
      app.passport.use(name, new Strategy(oauth1Settings, verifier.verify.bind(verifier)));
      app.passport.options(name, oauth1Settings);
github feathersjs / feathers / packages / authentication-oauth1 / lib / index.js View on Github external
if (!oauth1Settings.consumerKey) {
      throw new Error(`You must provide a 'consumerKey' in your authentication configuration or pass one explicitly`);
    }

    if (!oauth1Settings.consumerSecret) {
      throw new Error(`You must provide a 'consumerSecret' in your authentication configuration or pass one explicitly`);
    }

    const Verifier = options.Verifier || DefaultVerifier;
    const formatter = options.formatter || rest.formatter;
    const handler = options.handler || defaultHandler(oauth1Settings);
    const errorHandler = defaultErrorHandler(oauth1Settings);

    // register OAuth middleware
    debug(`Registering '${name}' Express OAuth middleware`);
    app.get(oauth1Settings.path, auth.express.authenticate(name, oauth1Settings));
    app.get(
      oauth1Settings.callbackPath,
      // NOTE (EK): We register failure redirect here so that we can
      // retain the natural express middleware redirect ability like
      // you would have with vanilla passport.
      auth.express.authenticate(name, oauth1Settings),
      handler,
      errorHandler,
      auth.express.emitEvents(authSettings, app),
      auth.express.setCookie(authSettings),
      auth.express.successRedirect(),
      auth.express.failureRedirect(authSettings),
      formatter
    );

    app.setup = function () {