Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allanShady/20732e80cf5a420f50d42ff5de83e75a to your computer and use it in GitHub Desktop.
Save allanShady/20732e80cf5a420f50d42ff5de83e75a to your computer and use it in GitHub Desktop.
#!/bin/bash
KC_REALM=<insert realm name here>
KC_USERNAME=<username here>
KC_PASSWORD=<password here>
KC_CLIENT=<client name here>
KC_CLIENT_SECRET=<client secret here>
KC_SERVER=<server address and port here>
KC_CONTEXT=auth
# Request Tokens for credentials
KC_RESPONSE=$( \
curl -k -v -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "username=$KC_USERNAME" \
-d "password=$KC_PASSWORD" \
-d 'grant_type=password' \
-d "client_id=$KC_CLIENT" \
-d "client_secret=$KC_CLIENT_SECRET" \
http://$KC_SERVER/$KC_CONTEXT/realms/$KC_REALM/protocol/openid-connect/token \
|jq .
)
echo Response=$KC_RESPONSE
KC_ACCESS_TOKEN=$(echo $KC_RESPONSE| jq -r .access_token)
KC_ID_TOKEN=$(echo $KC_RESPONSE| jq -r .id_token)
KC_REFRESH_TOKEN=$(echo $KC_RESPONSE| jq -r .refresh_token)
# Show all keycloak env variables
#set | grep KC_*
# Introspect Keycloak Request Token
curl -k -v \
-X POST \
-u "$KC_CLIENT:$KC_CLIENT_SECRET" \
-d "token=$KC_ACCESS_TOKEN" \
"http://$KC_SERVER/$KC_CONTEXT/realms/$KC_REALM/protocol/openid-connect/token/introspect" \
| jq .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment