当尝试使用keycloak java api即时通讯收到此错误时:
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
这是产生错误的代码:
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();
}
}
我理解此错误,但是我不明白为什么我收到此错误,领域已启用UMA,我的客户端已正确配置。有人可以帮助我吗?
使用了错误的UMA发现端点。它是uma 2配置,而不是uma配置(对于某些较旧的Keycloak版本有效):
http://${host}:${port}/auth/realms/${realm}/.well-known/uma2-configuration
文档:https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_authorization_api