-
-
Save pbrocks/f46d476fd3fb95bac9f3dad8f83b3f31 to your computer and use it in GitHub Desktop.
Bash script showing how to leverage az login to call Azure DevOps REST endpoints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Demo script to show how to leverage Azure DevOps CLI Extension to call DevOps REST API directly | |
## without the need for PAT token | |
# configuration | |
YOUR_AZURE_DEV_OPS_ORG='' | |
YOUR_AZURE_DEV_OPS_PROJECT_NAME='' | |
# Reverse Engineered this part by looking into Azure DevOps CLI Extension | |
# https://github.com/Azure/azure-devops-cli-extension/blob/8cf32a41126b2b66f130843d4d16de19290052b9/azure-devops/azext_devops/devops_sdk/client.py#L71 | |
# 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"}' \ | |
"https://dev.azure.com/$YOUR_AZURE_DEV_OPS_ORG/$YOUR_AZURE_DEV_OPS_PROJECT_NAME/_apis/distributedtask/environments?api-version=6.1-preview.1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment