pasee: Show error if any.

This commit is contained in:
Julien Palard 2019-07-02 16:14:20 +02:00
parent 47cbb795ef
commit 5f71bde9c6
1 changed files with 9 additions and 1 deletions

10
.bashrc
View File

@ -160,11 +160,19 @@ pasee()
local LOGIN
local PASSWORD
local HOST="${1:-https://id.meltygroup.com/tokens/?idp=meltygroup}"
local TEMP_DIR="$(mktemp --directory --suffix=pasee)"
read -p 'Login: ' LOGIN
read -s -p "Password for $LOGIN: " PASSWORD
echo
JWT="$(curl -s -XPOST -d '{"login": "'"$LOGIN"'", "password": "'"$PASSWORD"'"}' $HOST | jq -r ".access_token")"
curl -w '%{stderr}%{http_code}' -s -XPOST -d '{"login": "'"$LOGIN"'", "password": "'"$PASSWORD"'"}' "$HOST" > "$TEMP_DIR/stdout" 2> "$TEMP_DIR/stderr"
local HTTP_RESPONSE="$(<$TEMP_DIR/stdout)"
local STATUS_CODE="$(<$TEMP_DIR/stderr)"
JWT="$(jq -r ".access_token" <<< "$HTTP_RESPONSE")"
if [[ -z "$JWT" || "$STATUS_CODE" != "200" || "$JWT" == "null" ]]; then
printf "HTTP Error %s: %s\n" "$STATUS_CODE" "$HTTP_RESPONSE"
fi
AUTH="Authorization: Bearer $JWT"
rm -fr "$TEMP_DIR"
}
wyz()