Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const JwtStrategy = require('passport-jwt').Strategy;
- const ExtractJwt = require('passport-jwt').ExtractJwt;
- const jwtConfigurations = {
- jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
- secretOrKey: process.env.JWT_SECRET,
- issuer: 'accounts.examplesoft.com',
- audience: 'yoursite.net'
- }
- passport.use(new JwtStrategy(jwtConfigurations, jwtStrategyVerifyCallback));
- function jwtStrategyVerifyCallback (jwtPayload, done) {
- User.findOne({id: jwtPayload.sub}, function(err, user) {
- if (err) {
- return done(err, false);
- }
- if (user) {
- return done(null, user);
- } else {
- return done(null, false);
- // or you could create a new account
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement