Last active
August 4, 2020 10:13
-
-
Save malys/b0f2ce38bd2914ef58317318ef956fd5 to your computer and use it in GitHub Desktop.
[Probe for Keycloak integration] #keycloak #python #oauth2 #oidc #curl #bash
This file contains hidden or 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/bash | |
| # exit 1: service down | |
| # exit 0 && time <= 1500ms: service up | |
| # exit 0 && time > 1500ms: service deteriorated | |
| START=$(date +%s%N) | |
| REALM=xx | |
| CLIENT=xx | |
| USER=xxx | |
| PW=xxx | |
| URL=$1 | |
| #ex :https://xxxxx:8443/auth | |
| RESULT=`curl -s -k --data "grant_type=password&client_id=$CLIENT&username=$USER&password=$PW" $URL/realms/$REALM/protocol/openid-connect/token` | |
| #echo $RESULT | |
| TOKEN=`echo $RESULT | sed 's/.*access_token":"//g' | sed 's/".*//g'` | |
| A="$(cut -d'.' -f2 <<< $TOKEN)" | |
| echo $A | base64 --decode | python -m json.tool | |
| AUTH="Authorization: bearer $TOKEN" | |
| SIZE=$(echo -n $AUTH | wc -c) | |
| echo SIZE=$SIZE | |
| #echo $TOKEN | |
| INFO=`curl -s -X POST -k $URL/realms/$REALM/protocol/openid-connect/userinfo -H "$AUTH" -H "Content-Type: application/x-www-form-urlencoded"` | |
| NAME=`echo $INFO | sed 's/.*given_name":"//g' | sed 's/".*//g'` | |
| #echo $NAME | |
| END=$(date +%s%N) | |
| if [ "$NAME" = "$USER" ]; then | |
| DIFF=$((( $END - $START ) / 1000000)) | |
| # Time performance | |
| echo $DIFF | |
| exit 0 | |
| else | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment