java 如何在keycloak中添加自定义字段(属性)

8xiog9wr  于 2023-05-21  发布在  Java
关注(0)|答案(1)|浏览(221)

我想知道如何在Keycloak中添加自定义属性,以便用户可以在注册时填写额外的字段,而不是使用默认字段,此外,我可能还有一些额外的字段,我需要稍后从后端服务中填写

ki0zmccv

ki0zmccv1#

是的,你可以像这样在UserRepresentation对象中添加属性:

@Autowired
private final Keycloak keycloak;

public void createUser(UserDTO userDTO){
UserRepresentation user = new UserRepresentation();
user.setUsername(userDTO.getUsername());
user.setEmail(userDTO.getEmailAddress());
user.setFirstName(userDTO.getFirstName());
user.setLastName(userDTO.getLastName());
RealmResource realmResource = keycloak.realm(REALM);
UsersResource userRessource = realmResource.users();
Map<String, List<String>> attr = new HashMap<>;// create your attr
user.setAttributes(attr);
// Create user
Response result = userRessource.create(user);
}

相关问题