Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -e
- cd "${0%/*}"
- LOCAL_ONLY="$(pwd)/local_only/local_only.sh"
- if [ -f "$LOCAL_ONLY" ]; then
- . $(pwd)/local_only/local_only.sh
- fi
- cd $PROJECT_DIR
- encode() {
- local _length="${#1}"
- for (( _offset = 0 ; _offset < _length ; _offset++ )); do
- _print_offset="${1:_offset:1}"
- case "${_print_offset}" in
- [a-zA-Z0-9.~_-]) printf "${_print_offset}" ;;
- ' ') printf + ;;
- *) printf '%%%X' "'${_print_offset}" ;;
- esac
- done
- }
- CLIENT_ID=$(encode $CLIENT_ID)
- CLIENT_SECRET=$(encode $CLIENT_SECRET)
- RESOURCE_URI=$(encode "https://management.azure.com/")
- APP_TENTANT_ID=$(encode $APP_TENTANT_ID)
- FORMDATA="grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET"
- REQUEST_TOKEN=$(curl -s -X POST "https://login.microsoftonline.com/$APP_TENTANT_ID/oauth2/token" -H "Content-Type: application/x-www-form-urlencoded" -d "$FORMDATA" 2>&1)
- echo $REQUEST_TOKEN | python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement