C#C
C#3y ago
56 replies
JustiPhi

❔ Azure DevOps API Authentication issue (Managed Identity)

I am currently trying to add authentication to Azure managed Identity using Azure.Identity and Azure.Core in the following code:
var azureCredential = new DefaultAzureCredential();
var context = new TokenRequestContext(new string[] { $"{DevOpsURL}/.default" });
var token = await azureCredential.GetTokenAsync(context);

return token.Token;

I successfully get the token but when I try to use it in a bearer token auth header to get projects from
$"{DevOpsURL}/_apis/projects?api-version=7.0";


I get the following error
TF400813: The user 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' is not authorized to access this resource."


is there anything im missing as using a PAT (basic token auth header) from my own account works with the same fetch but using the managed identity one seems to not associate with an account

the app is running through azure app services and it is a system managed identity

Thanks
Was this page helpful?