angular - Angular JWT 包未正确验证我的令牌
问题描述
所以我使用 angular 7 和 @auth0/angular-jwt 包。我在某些路线上有一个身份验证守卫,我检查 jwt 令牌是否已过期。不管我做什么,这个方法总是说令牌已过期。我知道令牌是有效的,因为它们是邮递员。有人对这个 isTokenExpired 方法有经验吗?
import { Injectable } from '@angular/core';
import { JwtHelperService } from '@auth0/angular-jwt';
@Injectable({ providedIn: 'root' })
export class AuthService {
private jwtHelper = new JwtHelperService()
// ...
public isAuthenticated(): boolean {
const token = localStorage.getItem('token');
// Check whether the token is expired and return
// true or false
return !this.jwtHelper.isTokenExpired(token);
}
}
解决方案
你能在后端显示你设置为 exp 的内容吗?
如果您使用 'expiresIn',请记住它必须作为对象传递,如下所示:
{ expiresIn : '1h' }
推荐阅读
- php - 检查值是否在数组中并返回其余项目
- ios - SSL Pinning Alamofire 适用于任何证书
- python - 根据python中不同的二进制列创建分类列
- java - 播放框架应用程序路由中断
- java - 如何避免在 Java 中由 math.random 数字创建的数组中创建重复项?
- javascript - EOWEBBROWSER 文件数据追加
- javascript - 如何过滤带有子对象的对象
- javascript - javascript的Document.icon?
- javascript - 使用 ajax 和 XML 创建仪表板
- python - Pandas 使用字典过滤