Forum Discussion
Can't access http context user claims in Azure Function
That empty HttpContext.User is expected, not a bug — and it's the reason the rest of the checklist above won't get you anywhere. App Service authentication doesn't populate the user principal for .NET code running in Azure Functions. What it does instead is inject the claims into the request headers, and that's where your user and roles are hiding: the X-MS-CLIENT-PRINCIPAL header carries the full set of claims as Base64-encoded JSON. Read that header in the function, decode it, and look through its claims array — the role claim is in there as one of the entries, with its own claim type. Microsoft's own guidance on working with user identities in App Service authentication says exactly this, including that ClaimsPrincipal.Current isn't populated for Functions and that you take the claims from the headers or from a binding parameter instead.
Two things to check on your side before you test that. First, the roles claim only turns up if the user or group is actually assigned to the app role — defining the role in the app registration isn't enough on its own; the assignment happens under the enterprise application, in Users and groups. Second, the token the SharePoint app sends has to be issued for your function app's registration — if it's a token acquired for SharePoint or Graph, the function side won't accept it as its own identity, and the header won't be there at all. And one small correction to the reply above: changing the function's authorization level to Function or Admin is about function keys, not user identity — it won't populate claims either way.