Hello all,
Currently, init function in Keycloak JS adapter silently fails when Keycloak URL is unavailable or realm is wrongly configured.
The reason is how our 3rd party cookies support check works [1].
1. We create an iframe and a message callback that resolves a promise when a message is received from the iframe.
2. We return the promise and wait for it to be resolved
3. When promise is resolved successfully we continue with initialiation
The problem is, that when the message is never received in the callback (for example when Keycloak is not available or realm name is wrong), we never resolve the promise and hence the adapter is never initialized nor the error is reported.
Unfortunately, iframe doesn't have any onError callback, so we can't use it. We were considering 2 solutions to this:
1. Send a request before each 3rd party check which checks whether the Keycloak server is available and also whether specified realm exists. This works, however, sending a request with each init function call will cause a lot of useless network overhead especially in stable/production deployments where unavailability doesn't happen so often. See code for more details:
https://github.com/keycloak/keycloak/pull/7901/files
2. The other solution is to use timeout for 3rd party cookies check. The timeout mechanism for promises can be reused also for other parts of code in the future. The disadvantage is that we don't know the exact reason of failure, we just know that we didn't receive the message in specified time. This can also cause false errors in some unstable environments like mobile networks. Code:
https://github.com/keycloak/keycloak/pull/8161/files
WDYT? Which solution is better? Do you know about some better solution?
Best regards,
Michal