Skip to content

Instantly share code, notes, and snippets.

@mightyhorst
Forked from luciddreamz/keycloak.sh
Created April 19, 2019 01:57
Show Gist options
  • Save mightyhorst/8ca68a5172112e2057ff4bc10e5da4a5 to your computer and use it in GitHub Desktop.
Save mightyhorst/8ca68a5172112e2057ff4bc10e5da4a5 to your computer and use it in GitHub Desktop.
Keycloak Admin API Rest Example: Get User
#!/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 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment