【发布时间】:2018-11-07 10:04:10
【问题描述】:
我正在使用 angular 5 作为前端,使用 jersey 作为后端的 java 来制作 um 应用程序。当我尝试从前端角度消费时,我遇到了身份验证问题。这是客户端应用程序的代码:
const headers = {
'Content-Type': 'application/json',
'Authorization': this.auth.token
};
return this.http.get(this.url, { headers: headers, withCredentials: true })
.toPromise()
.then(this.extractData)
.catch(this.handleErrorPromise);
但是在寻找生成的请求时,我在我的服务器中找不到标头“授权”。我收到的只是:
主机:100.0.66.160:8092
连接:保持活动状态
编译指示:无缓存
缓存控制:无缓存
访问控制请求方法:GET
来源:http://localhost:4200
用户代理:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
访问控制请求标头:授权、内容类型
接受:*/*
接受编码:gzip,放气
接受语言:pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
那我没有找到验证的“授权”,有人可以告诉我那里有什么问题吗?
在服务器端遵循验证码:
String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
Autenticador autenticacao = new Autenticador();
String token;
extrairHeader(requestContext);
if (authorizationHeader != null && authorizationHeader.contains("Bearer ")) {
token = authorizationHeader.substring("Bearer ".length()).trim();
Key key = new KeyGenerator().generateKey();
return autenticacao.tokenValido(token, key);
} else {
return false;
}
【问题讨论】:
标签: java angular authentication oauth jax-rs