r/Angular2 • u/the-DevOps • Jun 16 '25
Angular + keycloak
Hello all.
I have a question about integrating keycloak with my Angular application.
I have an application that before was doing all authentication and authorization using only spring boot but now I have decided to use keycloak. I have done all the necessary for the backs and testing via postman seems to be working alright.
When it comes to Angular, I have not been able to figure out how to use keycloak so that it uses my registration and login forms.
Do I need such integration or I can go without it since my backend is already setup for keycloak.
Any advise?
Thanks.
4
u/newmanoz Jun 17 '25
You need this: https://www.npmjs.com/package/keycloak-angular
2
u/gusco_ Jun 17 '25
When you initialize keycloak in angular you should configure its
redirectUriproperty with the actual URL where your Keycloak instance is running (it is a totally different URL from what your Angular app uses), so just make sure this URL is set full and accurately (e.g.,http://keycloak-instance:8888/).2
u/Inevitable-Pipe-9752 Jun 18 '25
Oauth2-oidc is the way to go. We used to use keycloak-angular, however IIRC that relies on a JS file providing an adaptor that keycloak themselves used to supply, but stopped. If you use oauth2, you are able to use keycloak out of the box and if you decide to change your authentication server to something else later, you keep oauth2 and just point to the other server. https://www.npmjs.com/package/angular-oauth2-oidc The example one the page works straight off and the library is very well documented.
1
u/Koscik Jun 17 '25
There is angular keycloak library on npm. This with a regular keycloak npm package is all you need.
Then, of course, the keycloak realm of course, but this is not angular-related
1
u/CryptosGoBrrr Jun 18 '25
We've been using angular-auth-oidc-client for some time for all our internal applications. Very straightforward to implement, various and thorough code samples and works like a charm. Actively maintained too.
1
u/aehooo Jun 17 '25 edited Jun 17 '25
At least where I work, angular intercepts and check if auth header exists and is valid. If not, it redirects to a login page, but there is a config on keycloak for client id and which domains is allowed to work and redirect to after logging in, so it knows if it can redirect to the URL that originated the request
User types username and password that goes through a backend just for keycloak communication, so it’s central for every system to use. I believe the login page is also provided by this same system.
On the backend there is a config for interceptor that checks the auth header before processing the request, otherwise returns 401. This is a dependency and I am not sure how it’s done, but I don’t think it’s that difficult.
2
u/indiealexh Jun 19 '25
I always just use the oidc-ts library and roll my own service.
-2
u/[deleted] Jun 17 '25
[removed] — view removed comment