pnp / pnp/cli-microsoft365

Bug report: Federated Identity for ADO fails refreshing a token

Open
#6,727 1 comment 3 reactions 1 assignee View on GitHub

@martinlingstuyl is already working on this.

Since May 14, 2025.

bug keep-open
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.