[KEYCLOAK-12109] - Resolving authz discovery url using KeycloakUriBuilder

This commit is contained in:
Pedro Igor 2019-12-12 20:23:19 -03:00 committed by Stian Thorgersen
parent 3bd193acd7
commit 946088d48d
3 changed files with 6 additions and 3 deletions

View file

@ -17,6 +17,8 @@
*/ */
package org.keycloak.authorization.client; package org.keycloak.authorization.client;
import static org.keycloak.constants.ServiceUrlConstants.AUTHZ_DISCOVERY_URL;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Objects; import java.util.Objects;
@ -26,6 +28,7 @@ import org.keycloak.authorization.client.resource.AuthorizationResource;
import org.keycloak.authorization.client.resource.ProtectionResource; import org.keycloak.authorization.client.resource.ProtectionResource;
import org.keycloak.authorization.client.util.Http; import org.keycloak.authorization.client.util.Http;
import org.keycloak.authorization.client.util.TokenCallable; import org.keycloak.authorization.client.util.TokenCallable;
import org.keycloak.common.util.KeycloakUriBuilder;
import org.keycloak.representations.AccessTokenResponse; import org.keycloak.representations.AccessTokenResponse;
import org.keycloak.util.JsonSerialization; import org.keycloak.util.JsonSerialization;
@ -239,8 +242,7 @@ public class AuthzClient {
throw new IllegalArgumentException("Configuration URL can not be null."); throw new IllegalArgumentException("Configuration URL can not be null.");
} }
configurationUrl += "/realms/" + configuration.getRealm() + "/.well-known/uma2-configuration"; configurationUrl = KeycloakUriBuilder.fromUri(configurationUrl).clone().path(AUTHZ_DISCOVERY_URL).build(configuration.getRealm()).toString();
this.configuration = configuration; this.configuration = configuration;
this.http = new Http(configuration, authenticator != null ? authenticator : configuration.getClientAuthenticator()); this.http = new Http(configuration, authenticator != null ? authenticator : configuration.getClientAuthenticator());

View file

@ -32,5 +32,6 @@ public interface ServiceUrlConstants {
public static final String CLIENTS_MANAGEMENT_UNREGISTER_NODE_PATH = "/realms/{realm-name}/clients-managements/unregister-node"; public static final String CLIENTS_MANAGEMENT_UNREGISTER_NODE_PATH = "/realms/{realm-name}/clients-managements/unregister-node";
public static final String JWKS_URL = "/realms/{realm-name}/protocol/openid-connect/certs"; public static final String JWKS_URL = "/realms/{realm-name}/protocol/openid-connect/certs";
public static final String DISCOVERY_URL = "/realms/{realm-name}/.well-known/openid-configuration"; public static final String DISCOVERY_URL = "/realms/{realm-name}/.well-known/openid-configuration";
String AUTHZ_DISCOVERY_URL = "/realms/{realm-name}/.well-known/uma2-configuration";
} }

View file

@ -1,6 +1,6 @@
{ {
"realm": "authz-test", "realm": "authz-test",
"auth-server-url" : "http://localhost:8180/auth", "auth-server-url" : "http://localhost:8180/auth/",
"resource" : "resource-server-test", "resource" : "resource-server-test",
"credentials": { "credentials": {
"secret": "secret" "secret": "secret"