1

I'm trying to create user via KeycloakAdminClientService. Client is confidential and has user creation roles associated. not able to create the user, I'm getting forbidden 403 below is the code

UsersResource usersResource = kcProvider.getInstance().realm(realm).users(); CredentialRepresentation credentialRepresentation = createPasswordCredentials(user.getPassword());

    UserRepresentation kcUser = new UserRepresentation();
    kcUser.setUsername(user.getEmail());
    kcUser.setCredentials(Collections.singletonList(credentialRepresentation));
    kcUser.setFirstName(user.getFirstname());
    kcUser.setLastName(user.getLastname());
    kcUser.setEmail(user.getEmail());
    kcUser.setEnabled(true);
    kcUser.setEmailVerified(false);
    usersResource.create(kcUser);

I can fetch the token btw

Ashok
  • 41
  • 8
  • User needs to assign "manage_users" realm role. if not will get 403 error. [This is "view_users" role example.](https://stackoverflow.com/questions/73606410/which-api-should-use-to-get-user-permissions-list-by-userid-with-keycloak-admin/73607156#73607156) – Bench Vue Sep 22 '22 at 12:05
  • 1
    I've already done that. I've found the solutin. I need to disable csrf in SecurityConfig.configure() by adding http.csrf().disable(); – Ashok Sep 28 '22 at 06:22

0 Answers0