diff --git a/authorization.sh b/authorization.sh index f74dd12..4f31de7 100755 --- a/authorization.sh +++ b/authorization.sh @@ -1,9 +1,9 @@ BASEPATH=$(dirname $(realpath $0)) . $BASEPATH/.env -AUTH_TOKEN=$(echo $(curl --request POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' --data-urlencode client_id=sipgate-app-web --data-urlencode grant_type=password --data-urlencode username=$SIPUSER --data-urlencode password=$SIPPWD https://api.sipgate.com/login/sipgate-apps/protocol/openid-connect/token -s | jq '.access_token') | sed 's/\"//g') -if [ -z "$AUTH_TOKEN" ] || [ $AUTH_TOKEN = "null" ]; +AUTH_TOKEN=$(curl -o /dev/null -s -w "%{http_code}\n" --request GET --header 'Accept: application/json' --user $SIPUSER:$SIPPWD https://api.sipgate.com/v2/authorization/userinfo -s) +if [ $AUTH_TOKEN = "200" ]; then - echo "Login failed" + echo "Login OK" else - echo "Logged in" + echo "Login failed" fi