简体   繁体   English

Spring Boot + React + Keycloak after login 返回 No Access-Controll-Allow-Origin header 存在

[英]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.

相关问题 带有 Webflux 的 Spring Boot:请求的资源上不存在“Access-Control-Allow-Origin”标头 - Spring Boot with Webflux: No 'Access-Control-Allow-Origin' header is present on the requested resource <spring boot>请求的资源上不存在“Access-Control-Allow-Origin”header</spring> - <Spring Boot> No 'Access-Control-Allow-Origin' header is present on the requested resource 在反应应用程序 + spring 启动安全应用程序中获取“没有'访问控制允许来源'header 存在” - Getting "No 'Access-Control-Allowed-Origin' header is present" in react app + spring boot security app 反应使 axios 获取,返回错误:CORS 策略:请求的资源上不存在“Access-Control-Allow-Origin”标头 - React making axios get, returns error: CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource React JS - 请求的资源上不存在“Access-Control-Allow-Origin”header。 跨域资源错误 - React JS - No 'Access-Control-Allow-Origin' header is present on the requested resource. Cross Origin Resource Error 请求的资源上存在 Microsoft PowerBi React Access Token Error No 'Access-Control-Allow-Origin' header - MIcrosoft PowerBi React Access Token Error No 'Access-Control-Allow-Origin' header is present on the requested resource 理智/反应应用程序:访问 XMLHTTPREQUEST...'没有访问控制允许来源 header 存在' - Sanity/React app: Access to XMLHTTPREQUEST... 'No Access-Control-Allow-Origin header is present' LinkedIn OAuth 重定向登录返回“请求的资源上不存在‘Access-Control-Allow-Origin’标头”错误 - LinkedIn OAuth redirect login returning "No 'Access-Control-Allow-Origin' header is present on the requested resource" error React+ASP.NET.Core:请求的资源上不存在“Access-Control-Allow-Origin”标头 - React+ASP.NET.Core : No 'Access-Control-Allow-Origin' header is present on the requested resource 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 [Django反应设置] - No 'Access-Control-Allow-Origin' header is present on the requested resource. [Django-React Setup]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM