Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No 'Access-Control-Allow-Origin' header is present on the requested resource in keycloak

I am hitting Key cloak api http://localhost:8080/auth/realms/**/protocol/openid-connect/token with right credentials ,its working fine but with wrong credentials

enter image description here

And when I add the cross-origin-allow , it give me preflight error

can anyone please help me :) PS: everything is working fine with CORS plugin

like image 320
Nikhil Kapoor Avatar asked Oct 19 '25 09:10

Nikhil Kapoor


2 Answers

You are requesting a resource at localhost:8080 from you angular app which runs at locahost:4200.

In order for this to work you need to enable CORS on the server side. Thus you need to add the header to the response. This can either be done using the .htaccess file which has been proposed already. A better solution (or maybe the best one) is to configure this in your keycloak server. You can set allowed origins on the realm in which you are working. Simply open your admin console, navigate to the realm settings and set the 'Web origins'. The hint already tells you that you can configure 'Allowed CORS origins.' here.

Configure allowed CORS origins

For testing purpos you should add http://localhost:4200

like image 158
Tobias Amon Avatar answered Oct 21 '25 22:10

Tobias Amon


In our setup we used a keycloak.json for the communication between karaf and keycloak in this scenario it was necessary to add

"enable-cors": true

to our keycloak.json file. See also here

like image 44
Christian Avatar answered Oct 21 '25 21:10

Christian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!