【发布时间】:2018-09-10 05:45:37
【问题描述】:
尝试生成 Oauth2 令牌我使用了 Spring Boot Oauth2 和 Angular 5
在邮递员和 curl 中,我可以通过传递适当的值来生成令牌,并且使用相同的参数它在 Angular POST 中不起作用
错误
选项http://localhost:9999/auth-service/oauth/token 401 () 无法加载 http://localhost:9999/auth-service/oauth/token:响应 预检具有无效的 HTTP 状态代码 401。
角度代码
login2(credentials){
let headers = new Headers();
var creds = 'client_id=finance-service&client_secret=finance&grant_type=client_credentials&socpe=server';
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append("Authorization", "Basic " + btoa("finance-service:finance"));
console.log(btoa("finance-service:finance"))
return new Promise((resolve) =>{
this.http.post(SMSGlobal.authPath, creds, {headers : headers})
.subscribe((data) =>{
console.log(data.json());
},
(error) =>{
console.log(error);
})
})
}
我也在后端配置了 CORS
【问题讨论】:
-
如果出现这个错误,说明后台没有正确配置COS
-
呼!这可能有很多答案。提供的对您有用吗?
标签: angular spring-boot oauth-2.0