Skip to content

Instantly share code, notes, and snippets.

@thomasdarimont
Created August 29, 2019 19:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasdarimont/59cfa9ea629718f123ad22fbe319b946 to your computer and use it in GitHub Desktop.
Save thomasdarimont/59cfa9ea629718f123ad22fbe319b946 to your computer and use it in GitHub Desktop.
Keycloak get client by clientId
KC_CLIENT_ID=admin-cli
KC_SERVER=http://localhost:8080/auth

KC_REALM=master
KC_ISSUER=$KC_SERVER/realms/$KC_REALM
KC_USERNAME=admin
KC_PASSWORD=admin

# Fetch ACCESS_TOKEN
KC_RESPONSE=$( \
 curl \
 -d "client_id=$KC_CLIENT_ID" \
 -d "username=$KC_USERNAME" \
 -d "password=$KC_PASSWORD" \
 -d "grant_type=password" \
 -d "scope=profile roles" \
 "$KC_ISSUER/protocol/openid-connect/token" \
 )
echo $KC_RESPONSE | jq -C .
KC_ACCESS_TOKEN=$(echo $KC_RESPONSE | jq -r .access_token)

# Query clients by clientId
KC_CLIENT_RESPONSE=$( \
 curl -v \
 -H "Authorization: Bearer $KC_ACCESS_TOKEN" \
 "$KC_SERVER/admin/realms/demo/clients?clientId=svc-demo&viewableOnly=true" \
 )
echo $KC_CLIENT_RESPONSE | jq -C .
@mike-boost
Copy link

👍👍👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment