大家好, 当我尝试使用angular和keycloak令牌api获取keycloak令牌时,请出现此错误
错误:
错误对象{标头:对象,状态:0,状态文本:“未知 错误”,网址:null,确定:否,名称:“ HttpErrorResponse”,消息: “对(未知……)的Http故障响应,错误:错误} vendor.js:32928:5
**
跨源请求被阻止:同源策略禁止阅读 位于的远程资源 http://localhost:8080/auth/realms/Demo-Realm/protocol/openid-connect/token。 (原因:CORS标头中缺少令牌“ access-control-allow-headers” CORS飞行前频道中的“ Access-Control-Allow-Headers”。
**
代码:
headerDict = {
"Content-Type": "application/x-www-form-urlencoded",
'Access-Control-Allow-Origin': 'http://localhost:8080/auth',
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS',
'Access-Control-Allow-Headers': ' Origin, Content-Type, Authorization, Content-Length, X-Requested-With',
'Accept': 'application/x-www-form-urlencoded'
}
requestOptions = {
headers: new HttpHeaders(this.headerDict),
};
data = {
'grant_type' : 'password',
'client_id' : 'admin-cli',
'username' : 'admin',
'password' : 'admin'
};
constructor(private http:HttpClient) {
this.http.post('http://localhost:8080/auth/realms/Demo-Realm/protocol/openid-connect/token',
this.data,this.requestOptions
).subscribe();
}
尽管我在keycloak管理控制台中将“ Web Origins”设置为“ *”
任何想法如何解决此问题?