Reputation: 67
I would like to use the Azure DevOps API to create a PAT for my user. But I'm unable to authenticate yet. In this document from Microsoft, they state that authentication is possible with a PAT, but it is not true. I'm getting a HTTP 203 with a Sign In page in response.
PS: I'm using Postman to test the API requests.
Upvotes: 3
Views: 23186
Reputation: 11
Also ran into this problem. For me this worked - Putting the email in base 64 in the username and the PAT in the password in Basic Auth.
Upvotes: 1
Reputation: 21
I'm late in the game but I'll add my answer if someone stumble upon this just like I did.
So I have tested with a token obtained with this Azure CLI command:
az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv
And it works using the rest-client VS Code extension like this:
@jwt=<PASTE JWT HERE>
@org=<YOUR ORG HERE>
###
GET https://vssps.dev.azure.com/{{org}}/_apis/tokens/pats?api-version=7.1-preview.1
Authorization: Bearer {{jwt}}
I hope this helps !
Upvotes: 1
Reputation: 112
I wanted to share how I successfully connected to the Azure DevOps API using a Personal Access Token (PAT) from a PowerShell script. While this might be a bit late, I hope it helps others who come across this.
First, you'll need to have a PAT created in your Azure DevOps account
Now, here's the PowerShell script :
# Define your Personal Access Token (PAT)
$pat = "YOUR_PERSONAL_ACCESS_TOKEN"
# Define the DevOps API URL
$jsonUrl = "YOUR_JSON_URL_HERE"
# Create headers with the PAT for authentication
$headers = @{
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($pat)"))
}
# Make the request with authentication headers
$jsonContent = Invoke-RestMethod -Uri $jsonUrl -Headers $headers
Upvotes: 2
Reputation: 551
This worked for me when sending a request with headers like so
'Authentication': 'Basic <Base-64 encoded PAT>'
You have to include ':'
at the beginning of your PAT before you encode it (use Base-64 with padding).
Use a colon even if you do not include username.
P.S I think in Postman you don't need to encode your PAT.
Upvotes: 5
Reputation: 151
I think the security section of this REST API is misleading.
In fact, this REST API cannot be authenticated with PAT, as mentioned in another document:
To use the API, you must authenticate with an Azure AD token.
Unlike other Azure DevOps Services APIs, users must provide an Azure AD access token to use this API instead of a PAT token. Azure AD tokens are a safer authentication mechanism than using PATs. Given this API’s ability to create and revoke PATs, we want to ensure that such powerful functionality is given to allowed users only.
This document also explains how to use this REST API in detail, which you can refer to.
Upvotes: 2
Reputation: 861
Yes it does work, you're just not setting it up right.
Look at the Basic Authentication of this document. You need to base 64 encode the username password like this: username:PAT
. Spearate the two with the colon.
Upvotes: 5