Created
May 8, 2020 13:05
-
-
Save burnedikt/4cb116766023decdd60d676359718234 to your computer and use it in GitHub Desktop.
Get users from keycloak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires jq to be installed --> https://stedolan.github.io/jq/ | |
# Create a suitable client supporting "Direct Auth" for your keycloak instance and remember its client credentials (id and secret) | |
# also see https://developers.redhat.com/blog/2020/01/29/api-login-and-jwt-token-generation-using-keycloak/ | |
CLIENT_ID=test | |
CLIENT_SECRET=test-secret | |
USERNAME=admin | |
PASSWORD=supersecure | |
KEYCLOAK_URL=https://your.keycloak.com | |
REALM_NAME=realm | |
# Obtain a valid access token | |
ACCESS_TOKEN=$(curl --silent --location --request POST "${KEYCLOAK_URL}/auth/realms/${REALM_NAME}/protocol/openid-connect/token/" \ | |
--header 'Content-Type: application/x-www-form-urlencoded' \ | |
--data-urlencode 'grant_type=password' \ | |
--data-urlencode "client_id=${CLIENT_ID}" \ | |
--data-urlencode "client_secret=${CLIENT_SECRET}" \ | |
--data-urlencode "username=${USERNAME}" \ | |
--data-urlencode "password=${PASSWORD}" \ | |
| jq -r '.access_token') | |
# Get the list of users | |
curl --verbose --location --request GET "${KEYCLOAK_URL}/auth/admin/realms/${REALM_NAME}/users" \ | |
--header "Authorization: Bearer ${ACCESS_TOKEN}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To check which users are in Role XYZ (which is not trivially possible as the admin area only exposes direct, but not effective assignments):