Disable user using keycloak Admin REST API

I was not able to find the specific endpoint to do it.
basically what i want to do in my keycloak server, i want to send the userId and disable that user from the keycloak server, so they are not able to log into the system anymore. (maybe re-enabled in the future)
Is this possibe ?

Here’s the methods:
Get user:
https://www.keycloak.org/docs-api/15.0/rest-api/index.html#_getuser
Update user:
https://www.keycloak.org/docs-api/15.0/rest-api/index.html#_updateuser
Get the user, update the returned representation to enabled:false and send the representation back to the update method.

Thank you for the reply! Could you give an example of Update user method? where does enabled:false goes? thank you in advance

  1. get the user
curl https://{host}/auth/admin/realms/test/users/1bf78083-6ad2-40f2-b5f7-5afb29698d8c \
--header "Accept: application/json" \
--header "Authorization: Bearer {token}"

returns

{
  "id": "1bf78083-6ad2-40f2-b5f7-5afb29698d8c",
  "createdTimestamp": 1636051542250,
  "username": "test@test.com",
  "enabled": true,
  "totp": false,
  "emailVerified": true,
  "firstName": "test",
  "lastName": "test",
  "email": "test@test.com",
  "disableableCredentialTypes": [],
  "requiredActions": [],
  "notBefore": 0,
  "access": {
    "manageGroupMembership": true,
    "view": true,
    "mapRoles": true,
    "impersonate": true,
    "manage": true
  }
}
  1. update the user
curl -X PUT https://{host}/auth/admin/realms/test/users/1bf78083-6ad2-40f2-b5f7-5afb29698d8c \
--header 'Content-Type: application/json' \
--header "Accept: application/json" \
--header "Authorization: Bearer {token}" \
-d '{"id":"1bf78083-6ad2-40f2-b5f7-5afb29698d8c","createdTimestamp":1636051542250,"username":"test@test.com","enabled":false,"totp":false,"emailVerified":true,"firstName":"test","lastName":"test","email":"test@test.com","disableableCredentialTypes":[],"requiredActions":[],"notBefore":0,"access":{"manageGroupMembership":true,"view":true,"mapRoles":true,"impersonate":true,"manage":true}}'

note that enabled in the json object was changed to false

1 Like

Thank you so much for providing so much time and effort with this example! Appreciated