我正在尝试将 AWS Cognito 集成到我的 Nestjs 应用程序中,因为 Nodejs 应用程序不支持将 secretOrKey 与 AWS Cognito 一起使用,我正在寻找一种使用 来实现此功能的方法secretOrKeyProvider
,但我需要帮助了解是否以及如果是,那么我该怎么做它。
这是我当前的 JwtStrategy 实现:
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ClaimVerifyResult, handler } from './jwt.verify';
import { AuthService } from './auth.service';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(private readonly authService: AuthService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: true,
secretOrKeyProvider: (_, token, done) => {
//token here is valid
//token has not expired
//calling {handler} function here will return a valid user entity
//calling done here with the valid user will still result in unauthorized
return token;
},
});
}
public async validate(
payload: any,
done: (err: Error | null, result: ClaimVerifyResult) => void,
) {
console.log('validating');
const userInfo = await handler(payload);
if (!userInfo) {
return done(new UnauthorizedException(), null);
}
done(null, userInfo);
}
}
我可以得到secretOrKeyProvider
反馈,但我似乎无法获得validate
要调用的函数。