passport.use(new BearerStrategy({}, function(token, done) { user = User.findByToken(token); if (user) return done(null, user); else return done(null, false); } ));
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.serializeUser((user, next) => { next(null, { username: user.cn, }); });
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)
passport.deserializeUser(async (id, done) =>{ const user = await UserModel.findById(id); //con BBDD //const user = users.filter(user => user.id === id); done(null, user) })
passport.use(new LocalStrategy(function(username, password, done) { fetchUser() .then(user => { if (username === user.username && password === user.password) { done(null, user) } else { done(null, false) } }) .catch(err => done(err)) }))
passport.use(new GoogleStrategy({ clientId: 'your-client-id', clientSecret: 'your-secret', callbackURL: 'http://localhost:' + (process.env.PORT || 3000) + '/auth/google/callback' }, function(token, tokenSecret, profile, done) { // retrieve user ... fetchUser().then(user => done(null, user)) } ))
passport.serializeUser(function(user, done) { done(null, user.id) })
passport.authenticate('email-local', (err, user, info, status) => { return settingLoginResult(user, ctx) })(ctx, next)
passport.use(new PasswordGrantStrategy({ tokenURL: 'http://localhost:3001/api/v1/oauth/token', clientID: 'democlient1', clientSecret: 'democlientsecret1', scope:'profile', grant_type: 'password', customHeaders: {"Authorization": "Basic ZGVtb2NsaWVudDE6ZGVtb2NsaWVudHNlY3JldDE=","scope":"profile"} }, function(accessToken, refreshToken, profile, done) { console.log("Details ",accessToken,profile); done(null, profile); }))
passport.deserializeUser((obj, next) => { next(null, obj); });
passport.deserializeUser(async function(id, done) { try { const user = await fetchUser() done(null, user) } catch(err) { done(err) } })
passport.use(new FacebookStrategy({ clientID: 'your-client-id', clientSecret: 'your-secret', callbackURL: 'http://localhost:' + (process.env.PORT || 3000) + '/auth/facebook/callback' }, function(token, tokenSecret, profile, done) { // retrieve user ... fetchUser().then(user => done(null, user)) } ))
passport.use(new TwitterStrategy({ consumerKey: 'your-consumer-key', consumerSecret: 'your-secret', callbackURL: 'http://localhost:' + (process.env.PORT || 3000) + '/auth/twitter/callback' }, function(token, tokenSecret, profile, done) { // retrieve user ... fetchUser().then(user => done(null, user)) } ))
passport.authenticate('username-local', (err, user, info, status) => { return settingLoginResult(user, ctx) })(ctx, next)