@@ -31,37 +31,23 @@ if ($env:SYSTEM_DEBUG -eq "true") {
31
31
Get-ChildItem - Path Env: - Force - Recurse - Include * - Exclude * TOKEN | Sort-Object - Property Name | Format-Table - AutoSize | Out-String
32
32
}
33
33
34
- function Get-OidcRequestUrl ()
35
- {
36
- # Get Service Connection ID
37
- Get-ChildItem - Path Env: - Recurse - Include ENDPOINT_DATA_* | Select-Object - First 1 - ExpandProperty Name `
38
- | ForEach-Object { $_.Split (" _" )[2 ] }
39
- | Set-Variable serviceConnectionId
40
- if (! $serviceConnectionId ) {
41
- throw " Unable to determine service connection ID"
42
- }
43
- $oidcRequestUrl = " ${env: SYSTEM_TEAMFOUNDATIONCOLLECTIONURI}${env: SYSTEM_TEAMPROJECTID} /_apis/distributedtask/hubs/build/plans/${env: SYSTEM_PLANID} /jobs/${env: SYSTEM_JOBID} /oidctoken?api-version=7.1-preview.1&serviceConnectionId=${serviceConnectionId} "
44
- Write-Debug " OIDC Request URL: ${oidcRequestUrl} "
45
- return $oidcRequestUrl
46
- }
47
-
48
34
function New-OidcToken ()
49
35
{
50
36
Write-Verbose " `n Requesting OIDC token from Azure DevOps..."
51
- Get-OidcRequestUrl | Set-Variable oidcRequestUrl
52
- Write-Debug " OIDC Request URL: ${oidcRequestUrl} "
37
+ $oidcRequestUrl = " ${env: SYSTEM_OIDCREQUESTURI} ?api-version=7.1&serviceConnectionId=${env: AZURESUBSCRIPTION_SERVICE_CONNECTION_ID} "
53
38
Invoke-RestMethod - Headers @ {
54
39
Authorization = " Bearer ${SystemAccessToken} "
55
40
' Content-Type' = ' application/json'
56
41
} `
57
42
- Uri " ${oidcRequestUrl} " `
58
- - Method Post | Set-Variable oidcTokenResponse
43
+ - Method Post `
44
+ | Set-Variable oidcTokenResponse
59
45
$oidcToken = $oidcTokenResponse.oidcToken
60
46
if (! $oidcToken ) {
61
- throw " Could not get OIDC token"
47
+ throw " Could not get OIDC token from ${oidcRequestUrl} "
62
48
}
63
49
if ($oidcToken -notmatch " ^ey" ) {
64
- throw " OIDC token in unexpected format"
50
+ throw " OIDC token from ${oidcRequestUrl} has unexpected format"
65
51
}
66
52
return $oidcToken
67
53
}
0 commit comments