'Token authentication (instead of PAT token) to Azure DevOps REST API via Azure DevOps Pipeline
I need to use the Azure DevOps Rest API in an Azure DevOps Pipeline. I know it's possible to connect through a PAT token, but there should be a way to use service principal to connect to Azure?
What do I have to change to obtain a bearer token when I run below's code in an Azure DevOps Pipeline?
Connect-AzAccount -WarningAction 'SilentlyContinue' | Out-Null
$Token = (Get-AzAccessToken -ResourceUrl "499b84ac-1321-427f-aa17-267ca6975798").Token # Resource url is for Azure DevOps REST API source: https://stackoverflow.com/questions/69996528/authenticate-azure-devops-api-call-without-using-a-pat
$AzureDevOpsAuthenticationHeader = @{Authorization = 'Bearer ' + $Token }
Solution 1:[1]
As per the MS DOC Currently, it is not possible. Azure DevOps API doesn't support non-interactive service access via service principals.
There is no access control of service principal in Azure DevOps.
Non- interactive ways follows
- PAT (Most Recommended way)
- Azure AD ROPC flow (Not recommended because while request we have expose the username and password)
Refer here for more information
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DelliganeshS-MT |
