Is there a way to do a custom redirect from Keycloak?

A use case that I have in place goes roughly like so:

A user with some cookies, when accessing Application A, gets redirected to Keycloak (to authenticate). Because of these cookies, if some conditions are met, I’d like to redirect the user now again from Keycloak’s login form to Application B, without the user interacting or doing anything on Keycloak itself.

Is there any way that I can redirect the user within the SPIs and authentication providers e.g. Login provider? Are there any redirection authenticator executions and flows that I can make use of, or do I have to come up with some custom logic? If so, is there any Keycloak context/request/response object that I can make use of to redirect the user?

You can set the redirect_uri when sending the user to Keycloak for authentication. If you know what the condition is in the cookie, check it before you redirect them to Keycloak, and set the redirect_uri.

Thanks for the reply @xgp

Yes, I can set that URL, but then I need Keycloak to redirect the user straight as they land on the login page. Can that be done?

You could certainly write a custom authenticator for that. Is the cookie that you need to inspect going to be sent to Keycloak (e.g. same domain)?