Question: frequent calls to auth endpoint url
Hello
I successfully managed to integrate my angular (Ionic4) mobile application with Keycloak v4.
However, I noticed that (once redirected and logged into KC) the authorization endpoint (eg: "http://localhost:8080/auth/realms/master/protocol/openid-connect/auth?client_id=....) is invoked every time I go into a new page !
See screenshot with all requests to KC:

As far as I know/understand, as soon as I received a valid token, there is no need to invoke KC again and again, upon each new page (with distinct url path) I visit.
For the sake of clarity, the observed pattern is:
- very first click on a secured page => redirection to KC => token obtained => entering AppAuthGuard.isAccessAllowed
- click on a secured page A => request to auth endpoint => entering AppAuthGuard.isAccessAllowed
- click on a secured page B => request to auth endpoint => entering AppAuthGuard.isAccessAllowed
- click on a secured page C => request to auth endpoint => entering AppAuthGuard.isAccessAllowed
- etc...
Is this a "normal" behaviour ? Does this lib assume a SPA (Single Page Application) ? Is it because of a wrong config at my side ?
Here is my Keycloak initialization:
...
await keycloak.init({
config: environment.keycloak,
initOptions: {
onLoad: 'check-sso',
checkLoginIframe: false,
flow: 'implicit',
},
loadUserProfileAtStartUp: false,
});
Hi @bligny, sorry for the delay.
...the authorization endpoint is invoked every time I go into a new page !... Is this a "normal" behaviour ?
No this is not the correct behaviour. After having a valid token it should go to the kc server when needed, like to refresh the token and so on. I didn't try this library with an Ionic app. We still need to create an example with it and it's great to know that you managed to make it work, although facing this problem. I believe this is happening probably due the ionic's router or because of a misconfiguration.
In a web app it goes to the KC server if you refresh your page. So, the KeycloakModule will be initialized again using the bearer stored in your browser. Take a look also on this: if you aren't loading the KeycloakModule every time.
Tks! :)
How are you linking to different pages? I'm rather new to Angular, and noticed this exact behavior when I was using regular href links instead of routerLink
Hum interesting track ! Being also an Angular newbee, I have used - in this proof-of-concept - regular href links. That might be the cause indeed...
Hum interesting track ! Being also an Angular newbee, I have used - in this proof-of-concept - regular href links. That might be the cause indeed...
This is definitely the cause. Using href instead of routerLink bypasses the angular url changing in actually opens/starts the angular application from scratch. So this should not be done this way as it eliminates all benefits of having a single page application.
I would suggest closing this issue.