Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bash script showing how to leverage az login to call Azure DevOps REST endpoints
## Demo script to show how to leverage Azure DevOps CLI Extension to call DevOps REST API directly
## without the need for PAT token
# configuration
# Reverse Engineered this part by looking into Azure DevOps CLI Extension
# First get access token for resource 499b84ac-1321-427f-aa17-267ca6975798
access_token=$(az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query 'accessToken' | xargs)
# Wrap it as BASIC Auth Credentials
basic_auth=$(printf ":$access_token" | base64 --wrap=0)
# X Headers are important
curl -v -X POST \
-H "Authorization: Basic $basic_auth" \
-H "X-TFS-FedAuthRedirect: Suppress" \
-H "X-VSS-ForceMsaPassThrough: True" \
-H "Content-Type: application/json" \
-d '{"name": "TEST", "description": "Test Env to demonstrate authentication via AZ CLI"}' \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment