Curl command not working , I want to read the access token from curl command response. I am using this as azure release pipeline task

Viewed 23

Below command I am using to get the authorization token

  $AUTHORIZATION=$(curl -X POST -H 'Content-Type: application/x-www-form-urlencoded' \
    https://login.microsoftonline.com/$(tenant-id)/oauth2/token \
    -d 'client_id=$(ado-app-id)' \
    -d 'grant_type=client_credentials' \
    -d 'resource=https%3A%2F%2Fmanagement.core.windows.net%2F' \
    -d 'client_secret=$(ado-secret)'
    )
    
    
    echo "$AUTHORIZATION"
    
    $TOKEN=$(echo -n $AUTHORIZATION| jq -r .access_token | tr -d'"')
1 Answers

Your curl does not look right.
This is what the Authorization Document says:

POST https://login.microsoftonline.com/ CSPTenantID/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: login.microsoftonline.com
Content-Length: 1212
Expect: 100-continue
Body:
resource=https%3a%2f%2fapi.partnercenter.microsoft.com&client_id=Application-Id&client_secret= Application-Secret&grant_type=refresh_token&refresh_token=RefreshTokenVlaue&scope=openid

You are missing some HTTP request headers.

-H 'Host: login.microsoftonline.com'
-H 'Expect: 100-continue'
-H "Content-Length: <length>"
-d '{"resource":"https%3a%2f2fapi.partnercenter.microsoft.com","client_id":"<Application-Id>","grant_type": "refresh_token","refresh_token": <RefreshTokenVlaue>,"client_secret": <Application-Secret>,"scope": <openid>}'  

LINK to AUTHORIZATION CODE FLOW USING REST API CALLS

Related