2
votes

when a try use keycloak java api im getting this error:

Exception in thread "main" java.lang.RuntimeException: Could not obtain configuration from server [http://localhost:8010/auth//realms/BLKRealm/.well-known/uma-configuration].
at org.keycloak.authorization.client.AuthzClient.<init>(AuthzClient.java:82)
at org.keycloak.authorization.client.AuthzClient.create(AuthzClient.java:56)
at org.keycloak.authorization.client.AuthzClient.create(AuthzClient.java:49)
at KeyCloackApiCaller.Caller.App.someLibraryMethod(App.java:14)
at KeyCloackApiCaller.Caller.App.main(App.java:26)
Caused by: org.keycloak.authorization.client.util.HttpResponseException: Unexpected response from server: 404 / Not Found
at org.keycloak.authorization.client.util.HttpMethod.execute(HttpMethod.java:92)
at org.keycloak.authorization.client.util.HttpMethodResponse$2.execute(HttpMethodResponse.java:48)
at org.keycloak.authorization.client.AuthzClient.<init>(AuthzClient.java:80)
... 4 more

This is the code that has generated the error:

import org.keycloak.authorization.client.AuthzClient;
import org.keycloak.representations.AccessTokenResponse;

public class App 
{
   public static boolean someLibraryMethod() {

   AuthzClient authzClient = AuthzClient.create();

   // send the authorization request to the server in order to
   // obtain an access token granted to the user
   AccessTokenResponse response = authzClient.obtainAccessToken("*****", "*****");

   return true;
 }  
 public static void main(String[] args)
 {
   someLibraryMethod();
 }
}

I understand this error, but I don't understand why i received this error, realm has UMA enabled, my client is properply configurated. Anyone can help me?

2
first of all trying to obtain your uma-configuration manually, from terminal via curl - V. Panchenko

2 Answers

3
votes

There is used wrong UMA discovery endpoint. It is uma2-configuration, not uma-configuration (it was valid for some older Keycloak version):

http://${host}:${port}/auth/realms/${realm}/.well-known/uma2-configuration

Doc: https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_authorization_api

1
votes

This problem was generated, because i use an outdated api.

To solve this, if you are using maven, set the correct version:

<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-authz-client</artifactId>
    <version>8.0.1</version>
</dependency>

Thank you for all help.