【发布时间】:2019-06-03 06:33:54
【问题描述】:
我使用“https://github.com/auth0/angular2-jwt”将 JWT 令牌发送到我的服务器,我在调试 http 请求(角度)时可以看到令牌,但在服务器(java)上找不到令牌
这是我的配置 jwt
JwtModule.forRoot({
config: {
headerName: 'API_TOKEN',
tokenGetter: function tokenGetter() {
return localStorage.getItem('API_TOKEN');
},
whitelistedDomains: ['localhost:8092'],
// blacklistedRoutes: ['https://localhost:8092/login'],
authScheme: ''
}
}),
我添加了一个 JwtHttpInterceptor 来调试我的请求:
@Injectable()
export class JwtHttpInterceptor implements HttpInterceptor {
constructor() {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req);
}
}
这是截图:JWT token in header request
但是服务器找不到这个令牌。
当我尝试使用 chrome 插件添加令牌时,它可以工作并且服务器可以找到我的令牌:token added with chrome pluging
你能帮帮我吗?
【问题讨论】:
-
你能发布所有的 Cookie 字段(主机、HttpOnly 等)吗?
-
你好 scottyseus,我不使用 Cookie,我将我的令牌存储到 localstorage 中,然后,对于服务器的 foreach 调用我从本地存储中获取它(我的令牌)并将其添加到请求的标头中,我不知道是否必须使用 cookie 和本地存储?感谢您的帮助
-
@Ahmed 不是强制性的,但随着保护的进行,cookie 会更安全。
标签: spring angular7 angular2-jwt