var secured = function *(next) { var _this = this; yield passport.authenticate("bearer", { session: false }, function*(err, user, info) { if (err) { throw err; } else if (!user) { _this.status = 401; _this.body = {error: "Please log in"} } else { _this.passport.user = user; yield next; } }); }
passport.authenticate('local', function*(err, user, info) { if (err) { throw err; } if (user === false) { _this.status = 401; } else { yield _this.login(user); _this.body = { user: user }; } }).call(this)
app.use( route.post("/login", async function (context, next) { const { username } = context.request.body; let strategies = ["ldapauth"]; if (process.env.NODE_ENV === "development") { // if the application runs in development mode we first try // to authenticate with the local strategy. if the local strategy // is not successful we try it again with ldap. // in production mode the local strategy is skipped. // this enables local development with multiple users / sessions. strategies.unshift("local"); } await passport.authenticate(strategies, { session: true, successRedirect: "/", failureRedirect: `/login?error&username=${username}`, })(context, next); }), );
router .post('/login', ctx => passport.authenticate('local', (err, user) => { if (!user) { ctx.throw(401, err); } else { ctx.body = user; return ctx.login(user); } })(ctx)) .get('/users/profile', auth.getLoggedUser) .get('/logout', (ctx) => { ctx.logout(); ctx.body = {}; }) .get('/auth/facebook', passport.authenticate('facebook')) .get( '/auth/facebook/callback', passport.authenticate('facebook', { successRedirect: '/facebook/success/', failureRedirect: '/', }), );
passport.authenticate('username-local', (err, user, info, status) => { return settingLoginResult(user, ctx) })(ctx, next)
passport.authenticate('email-local', (err, user, info, status) => { return settingLoginResult(user, ctx) })(ctx, next)