-
-
Save luciddreamz/83a888eedd9274b4045a3ab8af064faa to your computer and use it in GitHub Desktop.
Keycloak Admin API Rest Example: Get User
This file contains 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
#!/bin/bash | |
# requires https://stedolan.github.io/jq/download/ | |
# config | |
KEYCLOAK_URL=http://localhost:8080/auth | |
KEYCLOAK_REALM=realm | |
KEYCLOAK_CLIENT_ID=clientId | |
KEYCLOAK_CLIENT_SECRET=clientSecret | |
USER_ID=userId | |
export TKN=$(curl -X POST "${KEYCLOAK_URL}/realms/${KEYCLOAK_REALM}/protocol/openid-connect/token" \ | |
-H "Content-Type: application/x-www-form-urlencoded" \ | |
-d "username=${KEYCLOAK_CLIENT_ID}" \ | |
-d "password=${KEYCLOAK_CLIENT_SECRET}" \ | |
-d 'grant_type=password' \ | |
-d 'client_id=admin-cli' | jq -r '.access_token') | |
curl -X GET "${KEYCLOAK_URL}/admin/realms/${KEYCLOAK_REALM}/users/${$USER_ID}" \ | |
-H "Accept: application/json" \ | |
-H "Authorization: Bearer $TKN" | jq . |
Just as hint:
We had issues with passwords which contains non ASCII characters.
We were able to fix this by replacing:
-d "password=${KEYCLOAK_CLIENT_SECRET}" \
with
--data-urlencode "password=${KEYCLOAK_CLIENT_SECRET}" \
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Raw HTTP format:
Example using defaults: