java为accestype public的客户机使用KeyClope管理客户机以编程方式创建用户
我刚开始使用KeyClope,似乎遇到了障碍。我无法使用KeyClope admin client for java以编程方式创建用户。我的keydape服务器版本是8.0.0,library/jar版本也一样。当我尝试创建一个用户时,我的程序只是坐在那里等待,在日志中我可以看到登录错误
2019-12-03 20:10:19,842 WARN [org.keycloak.events] (default task-26) type=LOGIN_ERROR, realmId=root-admin, clientId=demo-app, userId=null, ipAddress=192.x.x.x, error=not_allowed, auth_method=oauth_credentials, grant_type=password, client_auth_method=client-secret
Keycloak keycloak = KeycloakBuilder.builder() //
.serverUrl("http://192.x.x.x:8080/auth") //
.realm("root-admin") //
.grantType(OAuth2Constants.PASSWORD) //
.clientId("demo-app")
.clientSecret("")////
.username("genghis khan") //
.password("1234") //
.build();
CredentialRepresentation credential = new CredentialRepresentation();
credential.setType(CredentialRepresentation.PASSWORD);
credential.setValue("12345678");
UserRepresentation user = new UserRepresentation();
user.setEnabled(true);
user.setUsername("michaeljackson");
user.setFirstName("michael");
user.setLastName("jackson");
user.setCredentials(Arrays.asList(credential));
Response resp=keycloak.realm("root-admin").users().create(user);
System.out.println(resp.getStatus());
我的客户端是一个面向公众的应用程序,所以它的访问类型设置为public,因此不会为它生成客户端密码,而且成吉思汗用户的角色是admin,根管理员域是由我创建的。需要关于如何使其工作的帮助吗
# 1 楼答案
尝试在管理控制台上启用
demo-app
客户端的“已启用直接访问授权”这一行表示您正在使用“资源所有者密码凭据授予”,需要启用它
另见: https://www.keycloak.org/docs/8.0/server_admin/index.html#oidc-clients