当try use keycloak java api im收到以下错误时:
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();
}
}
我理解这个错误,但我不明白为什么会收到这个错误,realm启用了UMA,我的客户端已正确配置。有人能帮我吗?
发布于 2019-12-15 17:53:46
使用了错误的UMA发现终结点。它是uma2-configuration,,而不是uma-configuration (它对一些较旧的Keycloak版本有效):
http://${host}:${port}/auth/realms/${realm}/.well-known/uma2-configuration
文档:https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_authorization_api
发布于 2019-12-17 02:42:28
这个问题的产生,是因为我使用了一个过时的api。
要解决此问题,如果您使用的是maven,请设置正确的版本:
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-authz-client</artifactId>
<version>8.0.1</version>
</dependency>
谢谢你所有的帮助。
https://stackoverflow.com/questions/59338450
复制相似问题