Keycloak-Uma配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keycloak-Uma配置相关的知识,希望对你有一定的参考价值。

当尝试使用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

以上是关于Keycloak-Uma配置的主要内容,如果未能解决你的问题,请参考以下文章

Keycloak 独立集群配置中是不是需要仲裁?

使用 docker-compose 时导入 keycloak 配置文件

通过 CLI 配置 Keycloak eventsListener

使用 Postgresql v13 配置 Keycloak v15

Springboot 集成keycloak admin-cli api

如何配置 keycloak-(nodejs-)connect 以使用 PKCE?