I am working on nestjs backend app.I have google access token from google auth playground and i want to retrieve user data from this token using jwt ex. like curl http://locahost:3000/user/profile -H "Authorization : Bearer jwt".I have used jwt strategy from stackoverflow Authenticate Google JWT in NestJs question but unable to get data getting unauthorized error. Below is my code and jwt strategy
JWT Stragy:
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private configService: ConfigService){
super({
secretOrKeyProvider: passportJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: 'https://www.googleapis.com/oauth2/v3/certs',
}),
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
issuer: 'https://accounts.google.com',
algorithms: ['RS256'],
});
}
async validate(payload: any): Promise<unknown> {
// const { email } = payload;
console.log('payload t',payload)
return payload;
}
}
App module:
@Module({
imports: [
PassportModule.register({ defaultStrategy: 'jwt' }),
// JwtModule.register({
// secretOrPrivateKey: 'secretKey',
// signOptions: { expiresIn: '60s' },
// }),
AuthModule
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
Auth module:
@Module({
imports: [
ConfigModule.forRoot(),
],
providers: [JwtStrategy],
exports: [JwtStrategy],
})
export class AuthModule {}