Hello Matthew Holmes,
I was happy to repost the solution you shared, and I’m glad it helped resolve your issue. Thank you for taking the time to document your workaround so that others facing the same problem can find an easy reference.
To make sure the .NET SDK picks up your federated token reliably in Azure Pipelines, write the $idToken
into the agent’s temporary directory and then export the three required environment variables before running any database migrations or other SDK calls.
For example, in your AzureCLI@2 or PowerShell task:
# write the OIDC JWT into a temp file
$tokenPath = "$(Agent.TempDirectory)\federated-token.jwt"
Set-Content -Path $tokenPath -Value $env:idToken
# export the values the SDK needs
$env:AZURE_CLIENT_ID = $env:servicePrincipalId
$env:AZURE_TENANT_ID = $env:tenantId
$env:AZURE_FEDERATED_TOKEN_FILE = $tokenPath
With those three variables in place, WorkloadIdentityCredential
(used by Microsoft.Data.SqlClient
and other Azure SDK libraries) will automatically find and use your token file for authentication. No further changes are required.