We are facing the following issue with our frontend (Angular 6, http://localhost:4200) calling the backend (SpringBoot, http://localhost:8080) :
Access to XMLHttpRequest at 'http://localhost:8080/typesorganisme' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
We are using Keycloak, and the blocked URL is protected.
Following properties has been set for the Keycloak server :
- Root Url : http://localhost:4200
- Valid Redirect URI’s : http://localhost:4200/*
- Web Origins : http://localhost:4200
(We also tried to put "*" in Web Origins, with no results)
And the following CORS properties are normally added to the header by this filter in our backend :
@Override
public void doFilter(final ServletRequest theServletRequest, final ServletResponse theServletResponse, final FilterChain theFilterChain) throws IOException, ServletException
{
final HttpServletResponse response = (HttpServletResponse) theServletResponse;
final HttpServletRequest request = (HttpServletRequest) theServletRequest;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET,POST,DELETE,PUT,OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "*");
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Max-Age", "180");
response.setHeader("Access-Control-Expose-Headers", "X-Total-Count");
theFilterChain.doFilter(theServletRequest, theServletResponse);
}
Have you any ideas to solve this ?
UPDATE
After changing the cors filter on my backend, I now have the Access-Control-Allow-Origin correctly exposed but I'm facing an infinite redirect loop on my requests :
Resulting on this Browser Error :
Failed to load resource: net::ERR_TOO_MANY_REDIRECTS