Our application would have two ways of authenticating for 2 users.
One way is the standard way with the redirection on our keycloak instance login page.
The other way tho, require us to manually call keycloak back-end for an access token due to the flows we would like to have right now.
The thing is, while we can obtain the token without any problems, we cannot feed our keycloak instance in the front-end correctly with this token.
We tried init but it did not work correctly with various options we tried. (note that the keycloak instance should be empty when we want to feed it with the new token)
But it seems it does not trigger some internal logic of the Keycloak Instance and barely work.
We spent a lot of time looking for answer, and most of time we found unanswered questions, or nothing better than the solution above.
I have the same issue. For now I use your method. But, as you said yourself, it barely works : I found a bug with a specific case.
It happens if :
in a first browser tab, I open my app passing the token as a param in the URL => it works. It authenticates to my app with your method.
in a second browser tab, I open my app again, but without passing the token as a param => it fails. I am redirected to the classic keycloak login page. Which is quite normal: if my app is launched that way, it has no information on the authentication (because your method is a trick that never really informs keycloak of the authentication).
I don’t find how to solve it. The proper way would be to inform keycloak of the authentication. But I guess if it would be easily possible, you wouldn’t have look for that tricky method…
The solution mentioned by @pjmalandrino works fine, thanks!
But the session is not kept after I refresh the page, which can be a problem. Did any of you find a solution for this?
This is probably because of missing values in cookies/local storage. But all these are defined by when login through the Keycloak UI (which I don’t want here for this case).