passport-jwt

NestJS JwtStrategy use configService to pass secret key

爱⌒轻易说出口 提交于 2021-02-04 16:08:45
问题 I have the JwtStrategy class from docs example (https://docs.nestjs.com/techniques/authentication): @Injectable() export class JwtStrategy extends PassportStrategy(Strategy) { constructor( private readonly authService: AuthService, private readonly configService: ConfigService, ) { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), secretOrKey: this.configService.getSecretKey, }); } // ... } When I am trying access this before calling super() I get an error. But I still want to

Asymmetric keys with passport jwt. Verify always returns Unauthorized

徘徊边缘 提交于 2020-06-24 13:49:28
问题 Working on an app, and I want security from the start, so I've created a private/public key pair, and I'm setting up passport-jwt like this: ( key is the public part of the keypair) (passport, key) => { const opts = { jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), secretOrKey: key }; passport.use( new JwtStrategy(opts, (payload, done) => { log.info({message: 'verifying the token', payload}); User.findById(payload.id) .then(user => { if (user) { return done(null, { id: user._id,