无法在密钥斗篷中创建用户.取得403状态 [英] cannot create user in the keycloak. Getting 403 status

查看:83
本文介绍了无法在密钥斗篷中创建用户.取得403状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以编程方式访问在密钥斗篷中创建用户.但是我得到403作为状态码.我正在关注以下链接.

I am trying to access the create a user in the keycloak programmatically. But I am getting 403 as a status code. I am following the below link.

https://technology.first8.nl/programmatically-adding-users -in-keycloak/

有人可以帮助我吗?提前谢谢

Can anyone help me? Thanks In advance

我已经使用以下代码创建用户

I have using the following code to create user

Keycloak kc = Keycloak.getInstance(
                     "http://{server name}:8080/auth",
                     "{realm name}", // the realm to log in to
                     "{useraname}", 
                     "{password}",  // the user
                     "{client id}",
                     "{client secret key}");

            CredentialRepresentation credential = new CredentialRepresentation();
            credential.setType(CredentialRepresentation.PASSWORD);
            credential.setValue("test123");
            UserRepresentation user = new UserRepresentation();
            user.setUsername("codeuser");
            user.setFirstName("sampleuser1");
            user.setLastName("password");

            user.setCredentials(Arrays.asList(credential));
            user.setEnabled(true);
            Response result = kc.realm("{realm name}").users().create(user);

response.status为403

response.status is coming as 403

推荐答案

我遇到了同样的问题.这就是我修复它的方式.

I faced the same issue. This is how i fixed it.

  1. 创建一个至少具有manage-users领域管理角色的角色
  1. Create a role that has at least a realm-management role of manage-users

服务器9.0.2的UI更新

  1. 转到客户的Scope选项卡,然后将该角色添加到您的Realm Roles
  1. Go to your client's Scope tab and add the role to your Realm Roles

这篇关于无法在密钥斗篷中创建用户.取得403状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆