@@ -668,6 +668,55 @@ function Get-GitHubActionsIsDebug {
668
668
Set-Alias - Name ' Get-GHActionsIsDebug' - Value ' Get-GitHubActionsIsDebug' - Option ' ReadOnly' - Scope ' Local'
669
669
<#
670
670
. SYNOPSIS
671
+ GitHub Actions - Get OIDC Token
672
+ . DESCRIPTION
673
+ Interact with the GitHub OIDC provider and get a JWT ID token which would help to get access token from third party cloud providers.
674
+ . PARAMETER Audience
675
+ Audience.
676
+ . OUTPUTS
677
+ String
678
+ #>
679
+ function Get-GitHubActionsOidcToken {
680
+ [CmdletBinding (HelpUri = ' https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_get-githubactionsoidctoken#Get-GitHubActionsOidcToken' )]
681
+ [OutputType ([string ])]
682
+ param (
683
+ [Parameter (Position = 0 )][AllowNull ()][string ]$Audience
684
+ )
685
+ [string ]$OidcTokenRequestToken = $env: ACTIONS_ID_TOKEN_REQUEST_TOKEN
686
+ [string ]$OidcTokenRequestURL = $env: ACTIONS_ID_TOKEN_REQUEST_URL
687
+ if (
688
+ $null -eq $OidcTokenRequestToken -or
689
+ $OidcTokenRequestToken.Length -eq 0
690
+ ) {
691
+ return Write-Error - Message ' Unable to get GitHub Actions OIDC token request token!' - Category ' ResourceUnavailable'
692
+ }
693
+ Add-GitHubActionsSecretMask - Value $OidcTokenRequestToken
694
+ if (
695
+ $null -eq $OidcTokenRequestURL -or
696
+ $OidcTokenRequestURL.Length -eq 0
697
+ ) {
698
+ return Write-Error - Message ' Unable to get GitHub Actions OIDC token request URL!' - Category ' ResourceUnavailable'
699
+ }
700
+ if ($null -ne $Audience -and $Audience.Length -gt 0 ) {
701
+ Add-GitHubActionsSecretMask - Value $Audience
702
+ [string ]$AudienceEncode = [System.Web.HttpUtility ]::UrlEncode($Audience )
703
+ Add-GitHubActionsSecretMask - Value $AudienceEncode
704
+ $OidcTokenRequestURL += " &audience=$AudienceEncode "
705
+ }
706
+ try {
707
+ [pscustomobject ]$Response = Invoke-WebRequest - Uri $OidcTokenRequestURL - UseBasicParsing - UserAgent ' actions/oidc-client' - Headers @ {
708
+ Authorization = " Bearer $OidcTokenRequestToken "
709
+ } - MaximumRedirection 1 - MaximumRetryCount 10 - RetryIntervalSec 10 - Method ' Get'
710
+ [ValidateNotNullOrEmpty ()][string ]$OidcToken = (ConvertFrom-Json - InputObject $Response.Content - Depth 100 ).value
711
+ Add-GitHubActionsSecretMask - Value $OidcToken
712
+ return $OidcToken
713
+ } catch {
714
+ return Write-Error @_
715
+ }
716
+ }
717
+ Set-Alias - Name ' Get-GHActionsOidcToken' - Value ' Get-GitHubActionsOidcToken' - Option ' ReadOnly' - Scope ' Local'
718
+ <#
719
+ . SYNOPSIS
671
720
GitHub Actions - Get State
672
721
. DESCRIPTION
673
722
Get state.
@@ -1341,6 +1390,7 @@ Export-ModuleMember -Function @(
1341
1390
' Exit-GitHubActionsLogGroup' ,
1342
1391
' Get-GitHubActionsInput' ,
1343
1392
' Get-GitHubActionsIsDebug' ,
1393
+ ' Get-GitHubActionsOidcToken,'
1344
1394
' Get-GitHubActionsState' ,
1345
1395
' Get-GitHubActionsStepSummary' ,
1346
1396
' Get-GitHubActionsWebhookEventPayload' ,
@@ -1439,6 +1489,7 @@ Export-ModuleMember -Function @(
1439
1489
' Get-GHActionsEvent' ,
1440
1490
' Get-GHActionsInput' ,
1441
1491
' Get-GHActionsIsDebug' ,
1492
+ ' Get-GHActionsOidcToken' ,
1442
1493
' Get-GHActionsPayload' ,
1443
1494
' Get-GHActionsState' ,
1444
1495
' Get-GHActionsStepSummary' ,
0 commit comments