How to use @feathersjs/authentication - 10 common examples

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 feathers-plus / generator-feathers-plus / test-expands / a-gens / js / test-authentication.test-expected / src1 / services / users-1 / users-1.hooks.js View on Github external
// Hooks for service `users1`. (Can be re-generated.)
const commonHooks = require('feathers-hooks-common');
const { authenticate } = require('@feathersjs/authentication').hooks;
// eslint-disable-next-line no-unused-vars
const { hashPassword, protect } = require('@feathersjs/authentication-local').hooks;
// !code: imports // !end

// ! code: used
// eslint-disable-next-line no-unused-vars
const { iff } = commonHooks;
// eslint-disable-next-line no-unused-vars
const { create, update, patch, validateCreate, validateUpdate, validatePatch } = require('./users-1.validate');
// !end

// !code: init // !end

let moduleExports = {
  before: {
    // Your hooks should include:
github feathers-plus / generator-feathers-plus / test-expands / graphql-auth.test-expected / src1 / services / nedb-2 / nedb-2.hooks.js View on Github external
// Hooks for service `nedb2`. (Can be re-generated.)
const commonHooks = require('feathers-hooks-common');
const { authenticate } = require('@feathersjs/authentication').hooks;
// eslint-disable-next-line no-unused-vars
const nedb2Populate = require('./nedb-2.populate');
// !code: imports // !end

// ! code: used
// eslint-disable-next-line no-unused-vars
const { iff } = commonHooks;
// eslint-disable-next-line no-unused-vars
const { create, update, patch, validateCreate, validateUpdate, validatePatch } = require('./nedb-2.validate');
// !end

// !code: init // !end

let moduleExports = {
  before: {
    // Your hooks should include:
github feathers-plus / generator-feathers-plus / test-expands / cumulative-2-test-auth.test-expected / src1 / services / users1 / users1.hooks.js View on Github external
before: {
    // Your hooks should include:
    //   find  : authenticate('jwt')
    //   get   : authenticate('jwt')
    //   create: hashPassword()
    //   update: hashPassword(), authenticate('jwt')
    //   patch : hashPassword(), authenticate('jwt')
    //   remove: authenticate('jwt')
    // ! code: before
    all: [],
    find: [ authenticate('jwt') ],
    get: [ authenticate('jwt') ],
    create: [ hashPassword() ],
    update: [ hashPassword(), authenticate('jwt') ],
    patch: [ hashPassword(), authenticate('jwt') ],
    remove: [ authenticate('jwt') ]
    // !end
  },

  after: {
    // Your hooks should include:
    //   all   : protect('password') /* Must always be the last hook */
    // ! code: after
    all: [ protect('password') /* Must always be the last hook */ ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },
github feathers-plus / generator-feathers-plus / test-expands / cumulative-6-generators.test-expected / src1 / services / nedb1 / nedb1.hooks.js View on Github external
// ! code: used
// eslint-disable-next-line no-unused-vars
const { iff } = commonHooks;
// eslint-disable-next-line no-unused-vars
const { create, update, patch, validateCreate, validateUpdate, validatePatch } = require('./nedb1.validate');
// !end

// !code: init // !end

let moduleExports = {
  before: {
    // Your hooks should include:
    //   all   : authenticate('jwt')
    // ! code: before
    all: [ authenticate('jwt') ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },

  after: {
    // ! code: after
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
github feathers-plus / generator-feathers-plus / test / cumulative-1-mongo.test-expected / src1 / services / nedb-1 / nedb-1.hooks.js View on Github external
// eslint-disable-next-line no-unused-vars
const foreignKeys = [
  'id',
  '_id',
  'nedb2Id'
];
// !end
// !code: init // !end

let moduleExports = {
  before: {
    // Your hooks should include:
    //   all   : authenticate('jwt')
    //   find  : mongoKeys(ObjectID, foreignKeys)
    // ! code: before
    all: [ authenticate('jwt') ],
    find: [ mongoKeys(ObjectID, foreignKeys) ],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },

  after: {
    // ! code: after
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
github feathers-plus / generator-feathers-plus / test-expands / graphql-auth.test-expected / src1 / services / nedb-2 / nedb-2.hooks.js View on Github external
// ! code: used
// eslint-disable-next-line no-unused-vars
const { iff } = commonHooks;
// eslint-disable-next-line no-unused-vars
const { create, update, patch, validateCreate, validateUpdate, validatePatch } = require('./nedb-2.validate');
// !end

// !code: init // !end

let moduleExports = {
  before: {
    // Your hooks should include:
    //   all   : authenticate('jwt')
    // ! code: before
    all: [ authenticate('jwt') ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
    // !end
  },

  after: {
    // ! code: after
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
github feathers-plus / generator-feathers-plus / test-expands / authentication-2.test-expected / src1 / services / users-1 / users-1.hooks.js View on Github external
// !end

// !code: init // !end

let moduleExports = {
  before: {
    // Your hooks should include:
    //   find  : authenticate('jwt')
    //   get   : authenticate('jwt')
    //   create: hashPassword()
    //   update: hashPassword(), authenticate('jwt')
    //   patch : hashPassword(), authenticate('jwt')
    //   remove: authenticate('jwt')
    // ! code: before
    all: [],
    find: [ authenticate('jwt') ],
    get: [ authenticate('jwt') ],
    create: [ hashPassword() ],
    update: [ hashPassword(), authenticate('jwt') ],
    patch: [ hashPassword(), authenticate('jwt') ],
    remove: [ authenticate('jwt') ]
    // !end
  },

  after: {
    // Your hooks should include:
    //   all   : protect('password') /* Must always be the last hook */
    // ! code: after
    all: [ protect('password') /* Must always be the last hook */ ],
    find: [],
    get: [],
    create: [],
github feathers-plus / generator-feathers-plus / test-expands / a-gens / ts / test-service.test-expected / src1 / authentication.ts View on Github external
let moduleExports = function (app: App) {
  const config = app.get('authentication');
  // !code: func_init // !end

  // Set up authentication with the secret
  app.configure(authentication(config));
  app.configure(jwt());
  app.configure(local());
  // !code: loc_1 // !end

  app.configure(oauth2(Object.assign({
    name: 'auth0',
    Strategy: Auth0Strategy,
    // !code: auth0_options // !end
  }, config.auth0)));

  app.configure(oauth2(Object.assign({
    name: 'google',
    Strategy: GoogleStrategy,
    // !code: google_options // !end
  }, config.google)));
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 jenkins-infra / evergreen / services / src / app.js View on Github external
app.service('authentication').hooks({
  before: {
    create: [
      (context) => {
        /* Stringify the signature JSON to make the lookup() function in
         * passport-local/utils happy
         *
         * Somewhat related to
         * https://github.com/jaredhanson/passport-local/issues/153
         */
        if (context.data.signature) {
          context.data.password = JSON.stringify(context.data.signature);
        }
        return context;
      },
      authentication.hooks.authenticate(['local', 'jwt'])
    ]
  }
});

/*
 * Initialize the Sentry backend integration for reporting error telemetry
 */
app.set('sentry', new Sentry(process.env.SENTRY_URL || app.get('sentry').url));

if (process.env.NODE_ENV != 'production') {
  app.configure(swagger({
    docsPath: '/apidocs',
    uiIndex: true,
    info: {
      title: 'Evergreen Backend APIs',
      description: