pnp / pnp/cli-microsoft365

Bug report: 'm365 spo serviceprincipal grant add' no longer works

Open
#7,126 10 comments 0 reactions 1 assignee View on GitHub

@pschaeflein is already working on this.

Since Mar 10, 2026.

bug work in progress
Dominant language
TypeScript
Stars
1.5k
Forks
413
Avg merge
5d 6h
Merged PRs (30d)
21

Description

Priority

(Urgent) I can't use the CLI

Description

Running the m365 spo serviceprincipal grant add command does not work.

Steps to reproduce
  • Log in with account that is Global Adminstrator
  • Run command: m365 spo serviceprincipal grant add --resource "<service-principal-object-id>" --scope "<service-principal-oauth2PermissionScope-value>"
    This command will fail with the message "Error: Request failed with status code 401".
  • Update the app registration used for the CLI to include the delegated permission "DelegatedPermissionGrant.ReadWrite.All". Grant admin consent for that permission.
    (Note: the m365 setup command does not include this permission)
  • Again, run the command Run command: m365 spo serviceprincipal grant add --resource "<service-principal-object-id>" --scope "<service-principal-oauth2PermissionScope-value>"
    The command will fail with the message "Error: The service principal for permssion request could not be found."
Expected results

Expect permission grant to be added to the service principal.

Actual results

The command fails as explained above.

Diagnostics

No response

CLI for Microsoft 365 version

11.4

nodejs version

22.16

Operating system (environment)

Windows

Shell

PowerShell

cli doctor

No response

Additional Info

As noted in #6757, the spo serviceprincipal grant add command should use Microsoft Graph.

I have confirmed using Graph Explorer. The following update allowed the web part code to work as expected:

POST /v1.0/oauth2PermissionGrants

{
  "clientId":"c99497e2-d09a-4b9a-8bea-ec29ef895c29",
  "consentType":"AllPrincipals",
  "resourceId":"e15131ab-a456-430f-9f20-936e000d5fa8",
  "scope":"access_as_user"
}

The clientId is the object id of the SharePoint Online Web Client Extensibility service principal.
The resourceId is the object id of the Enterprise Application to which permission is granted.

Although the web part worked normally, the API Access page shows a pending request that cannot be clear. (Rejecting returns the error a the top of the screenshot.)

Image

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.