()
| 9 | @Injectable() |
| 10 | export class JwtStrategy extends PassportStrategy(Strategy) { |
| 11 | constructor() { |
| 12 | super({ |
| 13 | // 提供从请求中提取 JWT 的方法。我们将使用在 API 请求的授权头中提供token的标准方法 |
| 14 | jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), |
| 15 | // 为了明确起见,我们选择默认的 false 设置, |
| 16 | // 它将确保 JWT 没有过期的责任委托给 Passport 模块。 |
| 17 | // 这意味着,如果我们的路由提供了一个过期的 JWT ,请求将被拒绝,并发送 401 未经授权的响应。Passport 会自动为我们办理 |
| 18 | ignoreExpiration: false, |
| 19 | // 使用权宜的选项来提供对称的秘密来签署令牌 |
| 20 | secretOrKey: App_configuration().secret, |
| 21 | passReqToCallback: true, |
| 22 | }); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * @description: 调用守卫验证 token |
nothing calls this directly
no outgoing calls
no test coverage detected