'How to configure other client redirect_uri's than '/sso/login' for Spring Boot client app?

I would like to avoid the default '/sso/login' redirect uri but instead be able to configure custom redirect URIs for my Spring Boot application.

I have added several redirect URI's in client configuration in Keycloak Admin console ("/sso/login" added only because it won't work otherwise right now)

But I am having trouble understanding how to configure the redirect_uri on the Spring Boot app side, e.g. currently it is being set to "/sso/login" by default in the query parameters. If I manually change the URL to have a different value for redirect_uri (one that is valid & entered in the Keycloak Admin console client configuration, for ex. "/customers"), then after authentication is completed, the "/customers" uri is attempted but responds with 302 and redirects to "/sso/login" with a 403 error and the error page is displayed.
Keycloak logs:

WARN  [org.keycloak.events] (default task-738) type=CODE_TO_TOKEN_ERROR, realmId=TestingRealm2, clientId=login-app, userId=4f1dab2b-81dc-4bdf-9c2c-6e4587a04eba, ipAddress=127.0.0.1, error=invalid_code, grant_type=authorization_code, code_id=276ab439-a093-4859-8bd4-7938a3525227, client_auth_method=client-secret

(Also in cases like this (some sort of error during authentication) I would like to have a specific redirect configured for errors or failures instead of "/sso/login?error=....". Is this possible?)

Note: If I attempt to access the "/customers" resource, I get redirected to Keycloak auth page, I complete it, then I am successfully redirected back to "/customers" on client app, however the "redirect_uri" value still points to "/sso/login".

Note: I created my Spring Boot app based on this example.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source