[英]Spring Boot + React + Keycloak after login returns No Access-Controll-Allow-Origin header is present
I am trying to add a frontend to my SpringBoot application.我正在尝试向我的 SpringBoot 应用程序添加前端。 I also have a users provider connected perfectly, because if I did a CURL it works.
我也有一个完美连接的用户提供商,因为如果我做了一个 CURL 它就可以工作。
The problem begins when connecting react to Keycloak to do a login, it shows the login page, but when the login is OK it returns
Access to XMLHttpRequest at 'http://localhost:18080/auth/realms/Realm/protocol/openid-connect/token' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
It still problem of Keycloak because it is working by CURL, but I could not reach to configure it well.它仍然是 Keycloak 的问题,因为它由 CURL 工作,但我无法很好地配置它。
I add a * in Web Origins of the Client also.我还在客户端的 Web 起源中添加了一个 *。
You won't reproduce CORS problem with curl
cause it is browser conventions.您不会使用
curl
重现CORS问题,因为它是浏览器约定。
Basically, the browser considers a request as a CORS when a client request contains:基本上,当客户端请求包含以下内容时,浏览器会将请求视为 CORS:
headers:
Origin: 127.0.0.1
Set-Fetch-Mode: cors
And server response must contain: Access-Control-Allow-Origin: *
where * can be changed for specific resources.并且服务器响应必须包含:
Access-Control-Allow-Origin: *
其中 * 可以针对特定资源进行更改。
See article about CORS and @CrossOrigin
annotation inside Spring请参阅 Spring 中有关 CORS 和
@CrossOrigin
注释的文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.