【发布时间】:2019-03-12 20:02:19
【问题描述】:
我需要向 Spring Boot OAuth 2 授权服务器发送发布请求以获取 JWT 令牌?使用 Postman 我得到了令牌并且 Auth Server 工作正常。但是对于 Angular,我很难找出正确的发布请求格式?
这是我目前使用的方法。
login() {
const url = 'http://localhost:9090/oauth/token';
const data = {
'grant_type': 'password',
'username': 'username',
'password': 'password'
};
const reqH = new HttpHeaders({
'Content-Type': 'application/x-www-urlencoded',
'Authorization': 'Basic ' + btoa('client-id' + ':' + 'secret'),
'grant_type': 'password',
'username': 'administrator%40divinedragon.com',
'password': 'password'
});
return this.http.post('http://localhost:9090/oauth/token', data, {
headers: reqH
});
}
使用此方法时出现以下错误。
HttpErrorResponse {headers: HttpHeaders, status: 400, statusText: "OK", url: "http://localhost:9090/oauth/token", ok: false, ...},
错误:{错误:“无效请求”,错误描述:“缺少授权类型”}
非常感谢您的帮助!
【问题讨论】:
-
您解决了这个问题吗?请问你是怎么解决的。
-
面临同样的问题。有人对此有答案吗?
标签: angular oauth oauth-2.0 jwt