Implemented client credentials flow with -ClientSecret
#24
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test Workload Identity authentication | |
on: pull_request_target | |
jobs: | |
authorize: | |
environment: | |
${{ github.event_name == 'pull_request_target' && | |
github.event.pull_request.head.repo.full_name != github.repository && | |
'external' || 'internal' }} | |
runs-on: ubuntu-latest | |
steps: | |
- run: true | |
test: | |
needs: authorize | |
permissions: | |
id-token: write # This is required for requesting the ID token of the pipeline | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha || github.ref }} | |
- name: Install and cache PowerShell modules | |
uses: potatoqualitee/[email protected] | |
with: | |
modules-to-cache: Pester, PlatyPS | |
- name: Build module | |
run: .\build.ps1 -RunTests None | |
shell: pwsh | |
- name: Get token | |
shell: pwsh | |
env: | |
TENANT_ID: ${{ secrets.TENANT_ID }} | |
CLIENT_ID: ${{ secrets.CLIENT_ID }} | |
run: | | |
$Url = $env:ACTIONS_ID_TOKEN_REQUEST_URL | |
$Params = @{ | |
'Uri' = "$Url&audience=api://AzureADTokenExchange" | |
'Headers' = @{ | |
'Authorization' = "Bearer $($env:ACTIONS_ID_TOKEN_REQUEST_TOKEN)" | |
} | |
} | |
$OidcTokenResponse = Invoke-RestMethod @Params | |
$OidcToken = $OidcTokenResponse.value | |
Import-Module .\AzAuth | |
Get-AzToken -WorkloadIdentity -ExternalToken $OidcToken -TenantId $env:TENANT_ID -ClientId $env:CLIENT_ID -ErrorAction Stop | Out-Null | |
Write-Host "Successfully retrieved token for Workload Identity." |