我刚刚开始使用密钥斗篷,似乎遇到了障碍。我无法使用Java的keycloak-admin-client以编程方式创建用户。我的keycloak服务器版本为8.0.0,库/ 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());
我的客户端是面向公众的应用程序,因此将访问类型设置为公共,因此不会为其生成任何客户端机密,成吉思汗用户也具有admin角色,而root-admin领域已由我创建。需要如何做这项工作的帮助
答案 0 :(得分:0)
尝试在管理控制台上启用demo-app
客户端的“已启用直接访问授权”。
.grantType(OAuth2Constants.PASSWORD) //
此行表示您正在使用“资源所有者密码凭据授予”,并且需要将其启用。
另请参阅: https://www.keycloak.org/docs/8.0/server_admin/index.html#oidc-clients