user image

Published in : 2022-02-26

React KeyCloak : keycloak js header Access-Control-Allow-Origin sent twice in response

React js

Hello I now integrate keycloak with my react app.

We admin the server to deal :

- https://localhost:xxxx
with the same domain as our keycloak server

With the second link we got the error

 we get CORS error : 

Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values ',, but only one is allowed.
keycloak.js:750          POST net::ERR_FAILED 200

 With the first link https://localhost:xxxx all is working fine.

The main difference I could see is in the two requests for cors in the request headers:


With the first link  https://localhost:xxxx

Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
With the second link 

Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site


Thanks for your help



nico Date : 2022-03-06

Best answers


Best answers


Hello I realised that the keycloak is behind a reverse-proxy HAProxy.

It is very likely that both keycloak first then HAProxy added the headers in the response… when we have the cors triggered !

I will ask this week the admin as he was on holidays.

I think my answer can help other people : remember to look at the full scope of the environment!

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

React usestate array map() is not working
Publish date: 2022-04-22 | Comments: 3

Tag: React js

useStyles Invalid hook call class component
Publish date: 2022-02-10 | Comments: 2

Tag: React js

import link as router link from 'react-router-dom' Reactjs
Publish date: 2021-09-30 | Comments: 3

Tag: React js

[Solved] Cannot read properties of null (reading 'getBoundingClientRect')
Publish date: 2021-12-02 | Comments: 2

Tag: React js

[solved] Render/Show a custom option in Autocomplete Material UI?
Publish date: 2021-12-22 | Comments: 2

Tag: React js

npm install @mui/material returns error
Publish date: 2022-04-02 | Comments: 1

Tag: React js

TypeError: Super expression must either be null or a function
Publish date: 2022-03-13 | Comments: 2

Tag: React js