Skip to content
Advertisement

Keycloak returns CORS Access-Control-Allow-Origin error

I am able to login to Keycloak using the keycloak-js client, however, when making a fetch request, I get the following error:

JavaScript

The post request I am making is

JavaScript

The keycloak settings are

  • Root URL: http://localhost:8080
  • Valid Redirect URIs: http://localhost:8080
  • Base URL: /
  • Admin URL: Empty
  • Web Origins: * // but I have also tried http://localhost:8080 and +

My app is running on http://localhost:8080

Advertisement

Answer

I managed to solve the problem. It was the format of the data I was sending to Keycloak. I need to URLEncode the FormData adding it to the body of the Fetch request. Also, was using data rather than body in the fetch request.

Anyway, I solved it by putting all the data into PostMan, getting it working in there and then taking the Auto Code generation that Postman provides to come up with this.

JavaScript
User contributions licensed under: CC BY-SA
11 People found this is helpful
Advertisement