@@ -23,17 +23,19 @@ Set-StrictMode -Version 3
2323. (Join-Path $PSScriptRoot Helpers ApiView- Helpers.ps1)
2424
2525# Get Bearer token for APIView authentication
26+ # In Azure DevOps, this uses the service connection's Managed Identity/Service Principal
2627function Get-ApiViewBearerToken ()
2728{
28- $audience = " api://apiview"
2929 try {
30- $tokenResponse = az account get-access - token -- resource $audience -- output json 2> $null | ConvertFrom-Json
31- if ($tokenResponse -and $tokenResponse.accessToken ) {
32- return $tokenResponse.accessToken
30+ $tokenResponse = az account get-access - token -- resource " api://apiview" -- output json 2>&1
31+ if ($LASTEXITCODE -ne 0 ) {
32+ Write-Error " Failed to acquire access token: $tokenResponse "
33+ return $null
3334 }
34- return $null
35+ return ( $tokenResponse | ConvertFrom-Json ).accessToken
3536 }
3637 catch {
38+ Write-Error " Failed to acquire access token: $ ( $_.Exception.Message ) "
3739 return $null
3840 }
3941}
@@ -99,7 +101,7 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
99101 $bearerToken = Get-ApiViewBearerToken
100102 if (-not $bearerToken ) {
101103 Write-Error " Failed to acquire Bearer token for APIView authentication."
102- return 401
104+ return [ System.Net.HttpStatusCode ]::Unauthorized
103105 }
104106
105107 $headers = @ {
@@ -150,7 +152,7 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
150152 $bearerToken = Get-ApiViewBearerToken
151153 if (-not $bearerToken ) {
152154 Write-Error " Failed to acquire Bearer token for APIView authentication."
153- return 401
155+ return [ System.Net.HttpStatusCode ]::Unauthorized
154156 }
155157
156158 $headers = @ {
0 commit comments