Azure DevOps: AZURE_FEDERATED_TOKEN not injected in pipeline using Workload Identity Federation

Matthew Holmes 20 Reputation points
2025-06-09T15:45:23.09+00:00

Effectively the same problem as here:
https://learn.microsoft.com/en-us/answers/questions/2241454/azure-devops-azure-federated-token-not-injected-in

Getting the error "The workload identity configuration wasn't provided in environment variables or through WorkloadIdentityCredentialOptions."

  • The login to Azure via the federated SP works
  • Oauth enabled on the ADO Organization
  • Agent is windows-latest
  • App registration was created by azure devops and federated credentials it inserted look correct.
Azure DevOps
{count} votes

Accepted answer
  1. Bodapati Harish 820 Reputation points Microsoft External Staff Moderator
    2025-06-11T11:02:09.6466667+00:00

    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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Matthew Holmes 20 Reputation points
    2025-06-10T13:30:43.98+00:00

    Microsoft suddenly stopped injecting into the agent the correct environment variables and also the token that normally gets written toC:/var/run/secrets/azure/tokens/azure-identity-token

    The environment variables in question are the ones used in, for example, Microsoft.Data.SqlClient which is inside entity framework for connecting to the database for database migrations when the connection string has Authentication=Active Directory Workload Identity;'

    So I manually did the below mapping and saving of the token to work around the issue by using the CLI task with addSpnToEnvironment set. Below is the mapping

    $env:AZURE_CLIENT_ID = $env:servicePrincipalId

    $env:AZURE_TENANT_ID = $env:tenantId

    Set-Content -Path "C:\.idtoken" -Value $env:idToken

    $env:AZURE_FEDERATED_TOKEN_FILE = "C:\.idtoken"


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.