How to use the koa-passport.authenticate function in koa-passport

To help you get started, we’ve selected a few koa-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 SystangoTechnologies / koach-sql / src / modules / v1 / auth / controller.js View on Github external
export async function authUser (ctx, next) {
	// user local authentication strategy
	try {
		return passport.authenticate('local', (err, user) => {
			if (err || !user) {
				ctx.throw(401)
			}
			const token = user.generateToken()
			const response = user.toJSON()
			delete response.password
			ctx.status = constants.STATUS_CODE.SUCCESS_STATUS
			ctx.body = {
				user: response
			}
			ctx.append('Authorization', token);
		})(ctx, next)
	} catch (error) {
		ctx.body = error;
		ctx.status = constants.STATUS_CODE.INTERNAL_SERVER_ERROR_STATUS
	}
github StormFireGame / game / config / routes.js View on Github external
passport.authenticate('bearer', { session: false }),
    heroesController.show
  );

  app.put('/heroes/me/increase/:area(skills)/:id',
    passport.authenticate('bearer', { session: false }),
    heroesController.increase
  );

  app.put('/heroes/me/increase/:area(abilities|parameters)/:name',
    passport.authenticate('bearer', { session: false }),
    heroesController.increase
  );

  app.patch('/heroes/me',
    passport.authenticate('bearer', { session: false }),
    heroesController.update
  );

  app.put('/heroes/me/change-password',
    passport.authenticate('bearer', { session: false }),
    heroesController.changePassword
  );

  // TODO: Think about sep heroes controller to sep
  //   things, complects, island, building
  app.del('/heroes/me/things/:id',
    passport.authenticate('bearer', { session: false }),
    heroesController.removeThing
  );

  app.put('/heroes/me/things/:id/dress',
github slava-lu / koa-jwt-auth / index.js View on Github external
router.get('/custom', async(ctx, next) => {

  await passport.authenticate('jwt', function (err, user) {
    if (user) {
      ctx.body = "hello " + user.displayName;
    } else {
      ctx.body = "No such user";
      console.log("err", err)
    }
  } )(ctx, next)

});
github 7kmCo / koa-example / routes / users.js View on Github external
router.post('/login', async (ctx, next) => {
	return passport.authenticate('local', (err, user) => {
    if (user === false) {
      ctx.body = { success: false }
      ctx.throw(401)
    } else {
      ctx.body = { success: true }
      return ctx.login(user)
    }
	})(ctx)
	await next()
})
github superalsrk / koa2-boilerplate / src / routes / auth.js View on Github external
router.post('/login', async (ctx, next) => {
    let middleware = passport.authenticate('local', async(user, info) => {
        if (user === false) {
            ctx.body = {
                'status' : 400
            }
        } else {
            await ctx.login(user)
            ctx.body = {
                user: user
            }
        }
    })
    await middleware.call(this, ctx, next)
})
github rusty1s / koa2-rest-api / server / auth / index.js View on Github external
export function isClientAuthenticated() {
  return passport.authenticate('client-basic', { session: false });
}
github entria / koa-passport-mongoose-graphql / src / server / auth / index.js View on Github external
export function isFacebookAuthenticatedCallback() {
  return passport.authenticate('facebook', {
    failureRedirect: '/login',
  });
}
github ddellamico / ionic-conference-api / src / api / auth / oauth2.js View on Github external
export function authorize() {
  return passport.authenticate('jwt', { session: false });
}
github entria / koa-passport-mongoose-graphql / src / server / auth / index.js View on Github external
export function isAuthenticated() {
  return passport.authenticate('jwt');
}
github moovel / teamchatviz / server / api / lib / auth.js View on Github external
export default api => {
  api.get('/auth/slack',
    async (ctx, next) => {
      ctx.session.returnURL = ctx.query.returnURL;
      delete ctx.query.returnURL;
      await next();
    },
    passport.authenticate('slack'));

  api.get('/auth/slack-admin', passport.authenticate('slack-admin', {
    state: 'admin'
  }));

  api.get('/auth/slack/callback', async (ctx) => {
    const name = ctx.query.state === 'admin' ? 'slack-admin' : 'slack';
    try {
      await passport.authenticate(name, {
        successRedirect: '/',
        failureRedirect: '/error',
      }, function(user, info, status) {
        if (user === false) {
          ctx.redirect('/error')
        } else {
          ctx.login(user);
          ctx.redirect(ctx.session.returnURL ? ctx.session.returnURL : '/');
          if (ctx.query.state === 'admin') {