Last active
December 22, 2021 22:21
-
-
Save msavy/9390bfcd497f3c683a1c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Remember to install jq (e.g. brew install jq; yum install jq; apt-get install jq) | |
set -e | |
RED='\033[0;31m' | |
NORMAL='\033[0m' | |
printf "${RED}Getting OAuth2 token from Keycloak (includes access_token, refresh_token, etc):${NORMAL}\n" | |
KEYCLOAK_RESPONSE=`curl -s -X POST http://127.0.0.1:8080/auth/realms/stottie/protocol/openid-connect/token -H "Content-Type: application/x-www-form-urlencoded" -d 'username=rincewind' -d 'password=apiman' -d 'grant_type=password' -d 'client_id=apiman'` | |
printf "$KEYCLOAK_RESPONSE \n\n" | |
printf "${RED}Parsing access_token field, as we don't need the other elements:${NORMAL}\n" | |
ACCESS_TOKEN=`echo "$KEYCLOAK_RESPONSE" | jq -r '.access_token'` | |
printf "$ACCESS_TOKEN \n\n" | |
printf "${RED}Accessing service via apiman using token - we will put it into the Authorization header:${NORMAL}\n" | |
curl -k -v -H "Authorization: Bearer $ACCESS_TOKEN" https://127.0.0.1:8443/apiman-gateway/Newcastle/EchoService/1.0 | |
printf "\n\n" | |
printf "${RED}You can also use the access_token query parameter instead if you wish. Let's try it:${NORMAL}\n" | |
curl -k -v https://127.0.0.1:8443/apiman-gateway/Newcastle/EchoService/1.0?access_token="$ACCESS_TOKEN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment