Last active
May 24, 2020 17:58
-
-
Save larsw/54115b2eaf5576392630e5ab5099a3ea to your computer and use it in GitHub Desktop.
Script for fetching access tokens from keycloak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
HOST="host" | |
PORT="8080" | |
REALM="master" | |
TOKEN_ENDPOINT="http://$HOST:$PORT/auth/realms/$REALM/protocol/openid-connect/token" | |
CLIENT_ID="TODO" | |
CLIENT_SECRET="TODO" | |
GRANT_TYPE="password" | |
USERNAME="TODO" | |
PASSWORD="TODO" | |
SCOPE=" " # space or whitespace delimited scope names. | |
RESPONSE_TYPE="token" | |
command -v jq >/dev/null 2>&1 || { echo >&2 "jq is required to run this script." } | |
command -v curl >/dev/null 2>&1 || {echo >&2 "curl is required to run this script." } | |
command -v base64 >/dev/null 2>&1 || {echo >&2 "base64 is required to run this script." } | |
curl -s \ | |
-S \ | |
-d "grant_type=$GRANT_TYPE" \ | |
-d "client_id=$CLIENT_ID" \ | |
-d "client_secret=$CLIENT_SECRET" \ | |
-d "username=$USERNAME" \ | |
-d "password=$PASSWORD" \ | |
-d "scope=$SCOPE" \ | |
-d "response_type=$RESPONSE_TYPE" \ | |
$TOKEN_ENDPOINT | \ | |
jq ".access_token" | \ | |
cut -d "." -f 2 | \ | |
base64 -d | \ | |
jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment