Bug report: Federated Identity for ADO fails refreshing a token
@martinlingstuyl is already working on this.
Since May 14, 2025.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 413
- Avg merge
- 5d 6h
- Merged PRs (30d)
- 21
Description
Ok, so the below yaml will fail:
- task: AzurePowerShell@5
displayName: 'Login using Service Connection'
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
azureSubscription: 'MyServiceConnection'
ScriptType: 'InlineScript'
azurePowerShellVersion: LatestVersion
Inline: |
m365 login --authType federatedIdentity
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
m365 spo app add # etc etc
It will fail on the second task, executing a command against sharepoint.
So the point is that the CLI tries to request an additional access token for a 'new' resource (SharePoint).
When signing in, it got an access token scoped to the MS Graph.
When executing an SPO command it will request a token scoped to the SPO API.
But the expected environment variables are empty in the second PowerShell task. So the task fails.
The best workaround would be to always use the AzurePowerShell task, like this:
- task: AzurePowerShell@5
displayName: 'Login using Service Connection'
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
azureSubscription: 'MyServiceConnection'
ScriptType: 'InlineScript'
azurePowerShellVersion: LatestVersion
Inline: |
m365 login --authType federatedIdentity
- task: AzurePowerShell@5
displayName: 'Get SPO stuff'
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
azureSubscription: 'MyServiceConnection'
ScriptType: 'InlineScript'
azurePowerShellVersion: LatestVersion
Inline: |
m365 spo app add # etc etc
But this shouldn't be necessary.
I suggest we save the system access token / OIDC Url / Subscription Id, App Id, tenant Id in the connection list.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.