Keycloak: REST API for managing users

While Keycloak is well documented, I found it really hard to get started. Hence, these notes.
admin-cli is a default client in a realm. We use that as the client_id to get an access token.

Get access token

curl –request POST ‘http://loc…


This content originally appeared on DEV Community and was authored by rounakcodes

While Keycloak is well documented, I found it really hard to get started. Hence, these notes.
admin-cli is a default client in a realm. We use that as the client_id to get an access token.

Get access token

curl --request POST 'http://localhost:8080/auth/realms/<realm-name>/protocol/openid-connect/token' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'username=<username>' \
    --data-urlencode 'password=<password>' \
    --data-urlencode 'grant_type=password' \
    --data-urlencode 'client_id=admin-cli'

Get users

 curl --request GET 'http://localhost:8080/auth/admin/realms/<realm-name>/users' \
        --header 'Content-Type: application/x-www-form-urlencoded' \
        --header 'Authorization: Bearer <access-token>'

Create a user

 curl --request POST 'http://localhost:8080/auth/admin/realms/<realm-name>/users' \
      --header 'Content-Type: application/json' \
      --header 'Authorization: Bearer <access-token>' \
      --data-raw '{"username":"<username>"}'

Set user password (use the Get users API to get user id)

 curl --request PUT 'http://localhost:8080/auth/admin/realms/<realm-name>/users/<user-id>/reset-password'
       --header "Content-Type: application/json"
       --header "Authorization: Bearer <access-token>"
       --data-raw '{"type":"password", "value":"<password>", "temporary": false}'

Send verify email

Pre-requisite: Configure Realm Email Settings)

curl --location --request PUT 'http://localhost:8080/auth/admin/realms/<realm-name>/users/<user-id>/send-verify-email' \
--header 'Authorization: Bearer <access-token>'


This content originally appeared on DEV Community and was authored by rounakcodes


Print Share Comment Cite Upload Translate Updates
APA

rounakcodes | Sciencx (2021-06-12T14:01:39+00:00) Keycloak: REST API for managing users. Retrieved from https://www.scien.cx/2021/06/12/keycloak-rest-api-for-managing-users/

MLA
" » Keycloak: REST API for managing users." rounakcodes | Sciencx - Saturday June 12, 2021, https://www.scien.cx/2021/06/12/keycloak-rest-api-for-managing-users/
HARVARD
rounakcodes | Sciencx Saturday June 12, 2021 » Keycloak: REST API for managing users., viewed ,<https://www.scien.cx/2021/06/12/keycloak-rest-api-for-managing-users/>
VANCOUVER
rounakcodes | Sciencx - » Keycloak: REST API for managing users. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/12/keycloak-rest-api-for-managing-users/
CHICAGO
" » Keycloak: REST API for managing users." rounakcodes | Sciencx - Accessed . https://www.scien.cx/2021/06/12/keycloak-rest-api-for-managing-users/
IEEE
" » Keycloak: REST API for managing users." rounakcodes | Sciencx [Online]. Available: https://www.scien.cx/2021/06/12/keycloak-rest-api-for-managing-users/. [Accessed: ]
rf:citation
» Keycloak: REST API for managing users | rounakcodes | Sciencx | https://www.scien.cx/2021/06/12/keycloak-rest-api-for-managing-users/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.