Setting required action on new keycloak user account

Viewed 10885

I am using a client to create a new keycloak user. Something like this:

keycloak.realm(realm)
        .users()
        .create(user);

The user variable is a UserRepresentation object, and I'm trying to add an Update Password required action:

user.setRequiredActions(singletonList("Update Password"))

User gets created ok, the problem is that I don't have the required action set

enter image description here

Not sure what I'm doing wrong, should I specify a different value in the required actions list?

Thanks

3 Answers

To find out all the possible required actions aliases, export your targeted realm as json from the admin interface. In the json you will find the "requiredActions" array in which all the legal actions are listed like so:

 "requiredActions": [
    {
      "alias": "CONFIGURE_TOTP",
      "name": "Configure OTP",
      "providerId": "CONFIGURE_TOTP",
      "enabled": true,
      "defaultAction": false,
      "priority": 10,
      "config": {}
    },
    {
      "alias": "terms_and_conditions",
      "name": "Terms and Conditions",
      "providerId": "terms_and_conditions",
      "enabled": false,
      "defaultAction": false,
      "priority": 20,
      "config": {}
    },

Just use the string under the "alias" tag when setting the list of required actions in the code.

Now in Keycloak 8.x you can use

UserResource.toRepresentation().setRequiredActions(...);

to manually trigger an action like "verify email" after changing the loginname.

Related