How to generate PAT for Azure DevOps using PAT Lifecycle Management API

Mayank Aggarwal 20 Reputation points
2023-09-30T14:21:08.84+00:00

Hey Everyone,

Hope you all are doing well,

I am trying to create an Azure DevOps Personal Access Token via PAT Lifecycle Management API to utilize Work Items API but I am getting 203 Non-Authoritative Information Error.

User's image

Here’s the curl request -

curl --location ‘https://vssps.dev.azure.com/mayankaggarwal9919/_apis/tokens/pats?api-version=7.1-preview.1
–header ‘Content-Type: application/json’
–header ‘Authorization: Basic [Redacted]’
–header ‘Cookie: VstsSession=%7B%22PersistentSessionId%22%3A%229e3cefcb-0bf3-42cb-b3e3-9c76748cb94d%22%2C%22PendingAuthenticationSessionId%22%3A%2200000000-0000-0000-0000-000000000000%22%2C%22CurrentAuthenticationSessionId%22%3A%2200000000-0000-0000-0000-000000000000%22%2C%22SignInState%22%3A%7B%7D%7D; X-VSS-UseRequestRouting=True’
–data ’
{
“displayName”: “new_token”,
“scope”: “app_token”,
“validTo”: “2023-12-01T23:46:23.319Z”,
“allOrgs”: true
}

I was able to generate a bearer token (that needs to be passed in the PAT API) by registering an app in Azure Active Directory and hitting the below-mentioned curl request in Postman -

curl --location ‘https://login.microsoftonline.com/{tenantid}/oauth2/token
–header ‘Content-Type: application/x-www-form-urlencoded’
–header ‘Cookie: fpc=Anwji51Th8BHmcdGaAhuKwcrrAAsAQAAAAbCo9wOAAAA; stsservicecookie=estsfd; x-ms-gateway-slice=estsfd’
–data-urlencode ‘grant_type=client_credentials’
–data-urlencode ‘client_id={clientid}’
–data-urlencode ‘client_secret={clientsecret}’
–data-urlencode ‘resource=https://management.azure.com/’

I tried passing the token to PAT Lifecycle API (the 1st curl request shared above) in different formats like API Key, Basic, and Bearer just to hit and try but got the same error for all of them. Here are the API permissions I have granted to the created app -

User's image

This is how my application's authentication settings look like -

User's image

I also tried generating a bearer token that needs to be passed to PAT API by running this command on Azure Local CLI - az account get-access-token but I am still receiving the same error on passing the generated token in the PAT Lifecycle API.

I am able to access this URL -https://dev.azure.com/mayankaggarwal9919 from the browser and I also made sure that there's no newline symbol in the passed Bearer token. It seems to me that this is happening because of a lack of some permissions which I am unable to figure out.

Any insights will be highly appreciated.

Best,
Mayank

Community Center | Not monitored
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.