Skip to content

Instantly share code, notes, and snippets.

@alanbchristie
Last active July 14, 2023 15:22
Show Gist options
  • Save alanbchristie/5b072f9e92aa11d1fb954f4e1bfa4d50 to your computer and use it in GitHub Desktop.
Save alanbchristie/5b072f9e92aa11d1fb954f4e1bfa4d50 to your computer and use it in GitHub Desktop.
Getting keycloak users with httpie and jq
# Get username and emails from a Keycloak realm
# assuming you've installed httpie and jq
#
# - https://httpie.io
# - https://jqlang.github.io/jq/
# Armed with a keycloak URL
# And realm and realm manager password
URL=example.com
REALM=blob
PASSWORD=blob1234
# You can get the realm-manager admin CLI token...
http --form POST https://${URL}/auth/realms/${REALM}/protocol/openid-connect/token \
grant_type=password \
client_id=admin-cli \
username=manager \
password=${PASSWORD}
# With this token you can get the users and their emails...
TOKEN=01234567890
http https://${URL}/auth/admin/realms/${REALM}/users \
"Authorization: bearer ${TOKEN}" | jq '[.[] | {username: .username, email: .email}]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment