Keycloak 无法获取访问令牌

Leo*_*ivì 2 java spring oauth-2.0 spring-boot keycloak

我正在尝试使用AuthzClient我的 Spring 应用程序从公共客户端获取访问令牌。

这是代码:

AuthzClient authzClient = AuthzClient.create();
AuthorizationRequest request = new AuthorizationRequest();
AuthorizationResponse response = authzClient.authorization(username, password)
                                .authorize(request);
String token = response.getToken();
Run Code Online (Sandbox Code Playgroud)

但我不断收到此错误消息:

org.keycloak.authorization.client.util.HttpResponseException:来自服务器的意外响应:400/错误请求/来自服务器的响应:{"error":"invalid_request","error_description":"客户端不支持权限"}

有人可以帮我弄清楚我做错了什么吗?

Koh*_*URA 5

首先,您需要为您的客户端启用授权服务。因此,您应该转到管理控制台上的客户端设置页面,然后单击Authorization Enabled切换到ON,然后单击Save按钮。

另请参阅: Keycloak 授权服务指南 - 2.3。启用授权服务