I have a spring / jhipster application, with a button to login to keycloak. When I click the login button, it brings me to keycloak, and the URL would look something like
https://keycloak.mydomain.com/auth/realms/my-realm/protocol/openid-connect/auth?response_type=code&client_id=myclient&redirect_uri=http://localhost:8080/login/oauth2/code/oidc
So in the above, I want to change the redirect_uri=http://localhost:8080/login/oauth2/code/oidc to something else.
So I added the below code in src/main/java/../config/AuthorizationServerConfig.java:
@Configuration
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Bean
PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients
.inMemory()
.withClient("myclient")
.secret(passwordEncoder().encode("mysecret"))
.scopes("resource:read")
.authorizedGrantTypes("authorization_code")
.redirectUris("https://new-url-I-want.com");
}
}
But even with the above change, the redirect_uri doesn't change at all. Anyone know why this is?
And more information on why I made those changes:
With OIDC's authorization code flow, the service provider (in this case my website) provides the identity provider (Keycloak) with the URI to redirect the user back to after successful authentication. However, per the Spring docs, "With the default configuration, while the Authorization Code Flow is technically allowed, it is not completely configured": https://docs.spring.io/spring-security-oauth2-boot/docs/current/reference/html5/#oauth2-boot-authorization-server-authorization-code-grant
The docs go on to state that "OAuth2 Boot does not support configuring a redirect URI as a property — say, alongside client-id and client-secret." so,
"To add a redirect URI, you need to specify the client by using either InMemoryClientDetailsService or JdbcClientDetailsService":
https://docs.spring.io/spring-security-oauth2-boot/docs/current/reference/html5/#registering-a-redirect-uri-with-the-client