When my PowerShell script runs locally, I use【 az login】 to log in to my account via a pop-up window, and then obtain a token to access the following powerplatform API without any issues
$response1 = Invoke-WebRequest `
-Method Get `
-Uri "https://api.powerplatform.com/powerpages/environments/xxxxxx/websites?api-version=2022-03-01-preview" `
-Headers $apiHeaders
When I migrated this script to GitHub Actions, used an OIDC application user to log in, obtained a token, and then tried to access the same API, a 401 error occurred("Message": "Response status code does not indicate success: 401 (Unauthorized).")
- name: Azure Login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
allow-no-subscriptions: true
enable-AzPSSession: true
- name: Get API Token
shell: pwsh
run: |
$TOKEN = az account get-access-token `
--resource "https://api.powerplatform.com/" `
--query accessToken -o tsv
"API_TOKEN=$TOKEN" | Out-File -FilePath $Env:GITHUB_ENV -Append
- name: Enable Website
shell: pwsh
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
./activeWebsite.ps1 `
Any guidance or best practices would be appreciated.