Not able to load keycloak authentication page from application, calling protected resource with ajax request

397 views Asked by At

I have configured keycloak for IAM with gatekeeper as a proxy. When I call protected resource from my angular application through ajax request, it's not redirecting me to login page of keycloak, although in browser request call its showing me request going for login page. Any help would be much appreciated.

enter image description here

1

There are 1 answers

0
jokarls On

To me, it sounds like you have set up Gatekeeper to only protect your backend resources? Otherwise, the redirect would happen when you try to access your frontend.

If you are running your frontend as a separate application you need to obtain a Bearer token from Keycloak and pass it along in your ajax request. You can use the JS adapter to do that: https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter

In that case, you should also configure Gatekeeper with the --no-redirect option, so that it denies any unauthorized request.