Keycloak CORS issue on logout redirect

余生颓废 提交于 2021-01-28 18:44:46

问题


I am using Keycloak 10.0.2 to secure the spring boot REST API's and Angular 9 for front end. The front end is served from the spring boot microservice running on http://localhost:8080. On the keycloak side the openid-connect client web origin is configured to allow all origins.
Spring boot spring security is configured to use the Keycloak as oauth2 client provider.

spring:
  security:
    oauth2:
      client:
        provider:
          keycloak:
            issuer-uri: https://abc-keycloak.abccloud.com/auth/realms/abc
            scope: openid, profile        

        registration:
          keycloak:
            client-id: localhost
            client-secret: xxxxx
            redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}"
      resourceserver:
        jwt:
          issuer-uri: https://abc-keycloak.abccloud.com/auth/realms/abc

The angular front end makes a logout API call http://localhost:8080/logout and is redirected to

 HTTP/1.1 302 Found  Location:
 https://abc-keycloak.abccloud.com/auth/realms/abc/protocol/openid-connect/logout?id_token_hint=xxxxxx
 

I am getting a CORS error in the Google Chrome browser

Access to XMLHttpRequest at 'https://abc-keycloak.abccloud.com/auth/realms/abc/protocol/openid-connect/logout?id_token_hint=xxxxxx&post_logout_redirect_uri=http://localhost:8080' (redirected from 'http://localhost:8080/logout') from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.


回答1:


It shouldn't be a API call (request in the backround). Whole browser should be navigated to that app logout URL (and then to Keycloak logout URL).



来源:https://stackoverflow.com/questions/64713413/keycloak-cors-issue-on-logout-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!