Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash -e
- 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" #&resource=$RESOURCE_URI"
- 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)
- ACCESS_TOKEN=$(echo "import json; token=json.loads('$REQUEST_TOKEN'); print(token[\"access_token\"])")
- python -c "$ACCESS_TOKEN"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement