MicrosoftDocs / vsts-rest-api-specs

MIT License
158 stars 114 forks source link

Azure DevOps Accounts List won't work for Service Principals #696

Open EmilienCourt opened 1 month ago

EmilienCourt commented 1 month ago

Hi !

I'm using Azure DevOps REST API version 7.1-preview.

I'm logging in using a Service Principal, which is a member of an Azure Dev Ops Organization.

Connect-AzAccount -CertificatePath $certificatePath -CertificatePassword $certificateSecurePassword -ServicePrincipal -Tenant $tenant -ApplicationId $appId -ErrorAction Stop

Once logged in, I'm requesting an Access Token for Azure DevOps :

$token = Get-AzAccessToken -ResourceUrl "499b84ac-1321-427f-aa17-267ca6975798" -ErrorAction Stop

I'm then getting my profile id :

$me = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.Token)"} -Method Get -ContentType "application/json" -ErrorAction Stop -Uri "https://app.vssps.visualstudio.com/_apis/profile/profiles/me?api-version=7.1-preview.1"
$me
coreAttributes : @{DisplayName=; PublicAlias=; EmailAddress=; CountryName=; Avatar=}
coreRevision   : 454689571
timeStamp      : 5/29/2024 2:39:31 PM
id             : 6b28f906-cb6c-6ef0-af0f-6d1a4d3444c7
revision       : 454689571
profileState   : custom

When I try to get the list of Organizations attached to this member, I get an empty array :

Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.Token)"} -Method Get -ContentType "application/json" -ErrorAction Stop -Uri "https://app.vssps.visualstudio.com/_apis/accounts?memberId=$($me.id)&api-version=7.1-preview.1"

count value
----- -----
    0 {}

I've tried changing the permissions associated with the Service Principal in Azure DevOps, unsuccessfully.


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.