Skip to content

Instantly share code, notes, and snippets.

@pandeybk
Forked from paoloantinori/keycloak.sh
Last active December 16, 2019 16:29
Show Gist options
  • Save pandeybk/784952460dfede61004b2dbd9308c80d to your computer and use it in GitHub Desktop.
Save pandeybk/784952460dfede61004b2dbd9308c80d to your computer and use it in GitHub Desktop.
Keycloak Admin API Rest Example
#!/bin/bash
export KEYCLOAK_URL="http://localhost:8080"
export USERNAME="admin"
export PASSWORD="password"
export CLIENT_ID="admin-cli"
export TKN=$(curl -X POST "$KEYCLOAK_URL/auth/realms/master/protocol/openid-connect/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=${USERNAME}" \
-d "password=${PASSWORD}" \
-d "grant_type=password" \
-d "client_id=${CLIENT_ID}" | jq -r ".access_token")
curl -X GET "$KEYCLOAK_URL/auth/admin/realms" \
-H "Accept: application/json" \
-H "Authorization: Bearer $TKN" | jq .
# Total user count
curl -X GET "${KEYCLOAK_URL}/auth/admin/realms/master/users/count" \
-H "Accept: application/json" \
-H "Authorization: Bearer $TKN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment