Authenticate to Azure DevOps using PAT token

 Author: Akhil M Anil || DevOps Engineer

For applications that interface with Azure DevOps Services, you must authenticate to gain access to resources like REST APIs. There are different ways to authenticate our applications with Azure DevOps Services. In this article we will use a personal access token (PAT) to authenticate into Azure DevOps.

A personal access token contains your security credentials for Azure DevOps. A PAT identifies you, your accessible organizations, and scopes of access. As such, they're as critical as passwords. Since PAT is as identical as a user credential many organizations restrict its usage in Azure DevOps Api's instead promote the usage of any other authentication method or store the PAT token in Key-Vaults and use them.

1. Let's create a PAT token in ADO. 

  • Sign into your organization
  • From the home screen select the user settings and select Personal Access Token.


  • Select +New Token. Give a name for the token, select the organization then set your token to automatically expire after a set number of days. Select the scopes for this token to authorize for your specific tasks.

  • When you're done, copy the token and store it in a secure location. For your security, it won't be shown again.

2. Now we can test using a REST API call in Postman

  • Go to postman web/ postman app.
  • Click on Request. For testing, we can use a Repositories-list REST API call (List-Repositories).
  • Paste the request url with your organization and project name.
  • Click on Authorization and select Basic Auth.
  • Provide your username and PAT token created as password.
  • Send the request.

  • We successfully authenticate using our PAT token and we got the response for the request.
3. Testing using Azure DevOps Pipelines 
I have already written a blog on Getting List of Repositories - Azure Repos List, Use this blog for your reference.


Connect me via:

References: 





Comments

Popular posts from this blog

Install Java silently using powershell in Azure Windows VM

Configure an Azure DevOps self-hosted Windows agent in Docker

List of Repositories - Authorize Rest API calls using Job Access Token