Share via

Sites.Selected per-site write grant returns 401 "not allowed in this context" for an Entra Agent ID identity (Preview), works for a normal service principal

Derek Morgan II 0 Reputation points
2026-06-12T22:46:49.7133333+00:00

Setup I have a headless app-only agent built on Microsoft Entra Agent ID (Preview). It authenticates through the Microsoft Entra Auth SDK sidecar 2-leg exchange, so the token subject is the agent identity, not the blueprint principal. I verified that in the sign-in logs.

The agent is granted Microsoft Graph Sites.Selected (application), and I added a per-site write grant on the target site via permissions with roles: ["write"]. permissions confirms the grant is present for the agent's appId.

Problem When the agent calls content to upload a file, Graph returns:

HTTP 401 - unauthenticated: Request is not allowed in this context

Reads against the same site under the agent token also fail the same way.

What I ruled out The identical code path, same site, same per-site Sites.Selected write grant, succeeds when the caller is a normal Entra app registration's service principal. It fails only when the caller is the agent identity. So this isn't the site grant, the drive path, or DisableCustomAppAuthentication. The single variable is the agent identity as the token subject.

Question Is Sites.Selected expected to be honored for Entra Agent ID identity tokens in the current Preview, or is SharePoint not yet accepting app-only agent-identity tokens? If it's supported, what am I missing? If it's a known Preview gap, is there a tracking item or ETA?

Tenant and app IDs available on request. Happy to share correlation IDs.

Microsoft Security | Microsoft Entra | Microsoft Entra ID

1 answer

Sort by: Most helpful
  1. AI answer

    2026-06-12T22:47:14+00:00

    SharePoint and Microsoft Graph Sites.Selected behave differently depending on the type of identity and token used. The available guidance in the context shows:

    • Sites.Selected is enforced per site, and access is granted only when:
      • The app has the Sites.Selected application permission.
      • A per-site permission (for example write) is granted via Microsoft Graph or PnP PowerShell.
      • The app uses an application-only access token (no user) to call SharePoint/Graph.
    • When these conditions are met, application-only access works for standard Microsoft Entra app registrations (service principals) and is explicitly documented and supported.
    • For the SharePoint tool with the agent API, the documentation explicitly states that application-only authentication is not supported and that user identity (identity passthrough) is required; app-only OBO tokens are rejected with AuthenticationError: AppOnly OBO tokens not supported by target service.

    In the provided material, there is no statement that SharePoint or Microsoft Graph currently support app-only access using Microsoft Entra Agent ID identity tokens in the same way as standard service principals. The troubleshooting guidance for the SharePoint tool instead emphasizes that:

    • Application-only identity is not supported for that tool.
    • User identity passthrough is required.

    Given this, the behavior described (standard service principal working with Sites.Selected while the agent identity fails with 401 "not allowed in this context") is consistent with a current limitation: the target SharePoint/Graph surface is not yet accepting app-only tokens issued for agent identities in the same way as for regular app registrations.

    The context does not provide any indication that this is already supported for Entra Agent ID, nor does it provide a tracking item or ETA for enabling it. It only documents the general Sites.Selected model and the requirement for user identity in the SharePoint tool scenario.

    The only fully documented and supported pattern in the context for SharePoint access is:

    1. Use a standard Microsoft Entra application registration with Sites.Selected application permission.
    2. Grant per-site permissions via Microsoft Graph (/sites/{siteId}/permissions) or PnP PowerShell (Grant-PnPAzureAdAppSitePermission).
    3. Use an application-only token for that app to access the selected sites.

    Until there is explicit documentation that SharePoint/Graph accept app-only agent identity tokens for Sites.Selected, the supported workaround based on the available material is to continue using a regular app registration/service principal for app-only Sites.Selected scenarios, or to use user identity passthrough where required.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

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