Azure Static Web Apps authentication returns clientPrincipal: null after successful login

Gregg Aguilar 0 Reputation points
2026-11-26T01:21:03.45+00:00

I am experiencing an authentication issue with Azure Static Web Apps on the Free hosting plan.

Configuration:

  • Built-in Simple authentication

GitHub and Microsoft Entra ID authentication

Custom administrator role: officewerks_admin

GitHub pull request preview environment

Managed Azure Functions backend

Troubleshooting completed:

Administrator invitation accepted and role assignment confirmed.

GitHub authorization and Azure consent completed.

Tested both Safari and Chrome, including private browsing.

Authentication cookie is created and transmitted.

Authentication callbacks complete and redirect to the website.

The /.auth/me endpoint consistently returns {"clientPrincipal": null}.

Azure Diagnose and solve problems returns an error.

The website, Azure Functions API and Cosmos DB connectivity are working.

Is there a known issue with built-in authentication or session validation in Static Web Apps preview environments? What additional troubleshooting steps are recommended?

Azure Static Web Apps
Azure Static Web Apps

An Azure service that provides streamlined full-stack web app development.

0 comments No comments

1 answer

Sort by: Most helpful
  1. AI answer

    2026-11-26T01:22:08.4533333+00:00

    A successful provider callback followed by {"clientPrincipal":null} means the preview URL has no valid Static Web Apps session, so first compare the same login flow on the production and PR-preview hostnames to isolate an environment-specific platform failure.

    1. Isolate production versus preview

    Run these tests without changing consent, role assignments, or browsers again:

    1. On the production default azurestaticapps.net hostname, open:
      • /.auth/login/github, then /.auth/me
      • /.auth/login/aad, then /.auth/me
    2. Repeat on the exact PR URL posted by the GitHub deployment bot.
    3. Record the result as a matrix:
    Host GitHub Entra ID
    Production default hostname principal/null principal/null
    PR-preview hostname principal/null principal/null

    For an authenticated request, /.auth/me must return a client-principal object; null is the documented unauthenticated result.^1^ Therefore, the accepted officewerks_admin invitation cannot explain a null principal—the custom role is evaluated only after a principal exists.

    Built-in GitHub and Entra ID authentication is supported on all Static Web Apps plans, including Free.^2^ Free also supports up to three preview environments, so the hosting plan itself is not an authentication exclusion.^3^

    2. Validate hostname continuity

    PR environments have their own temporary hostname, and custom domains do not work with preview environments.^4^ During one test, verify in the browser network trace that:

    1. Login starts on the PR-preview hostname.
    2. The callback returns to that same PR-preview hostname.
    3. The final page and /.auth/me request remain on that hostname.
    4. No application code redirects to the production or custom domain after callback.
    5. The session cookie’s domain and path permit it to accompany the preview-host /.auth/me request.

    For custom authentication, the documented callback pattern is:

    https://<YOUR_SITE>/.auth/login/<PROVIDER_NAME_IN_CONFIG>/callback
    

    For Entra ID, the provider name is aad.^5^ You are using preconfigured authentication, so do not add a custom provider merely to troubleshoot this; custom authentication requires Standard and disables the preconfigured providers.

    If Azure Front Door or another reverse proxy is involved, bypass it and repeat the test directly against the preview hostname. Hostname changes through a proxy can break cookies and redirect URLs; preserving the original host is the recommended approach for Static Web Apps behind Front Door.^6^

    3. Check whether the failure is platform-side

    A preview-only failure affecting both GitHub and Entra ID, while production succeeds, strongly narrows the problem to the preview environment’s session/callback processing rather than provider consent or the custom role.

    There is no documented general limitation stating that built-in authentication is unsupported in PR previews. However, Microsoft has previously confirmed a Static Web Apps incident where one hosted identity backend failed and a later deployment succeeded after being routed to a healthy backend.^7^

    As a low-risk discriminating test:

    1. Push a no-op commit to the existing PR to redeploy its environment.
    2. Retest /.auth/me on the same PR URL.
    3. If practical, create a second temporary PR and test its new preview environment.
    4. Compare callback requests in the network traces, especially:
      • callback hostname;
      • HTTP status;
      • any identity.<number>.azurestaticapps.net hostname;
      • Set-Cookie response;
      • UTC timestamp and request/correlation IDs.

    A successful new preview while the original remains broken is useful evidence of an environment or identity-backend issue; redeployment is not a guaranteed repair.

    4. Escalate with a minimal reproducible package

    Since Diagnose and solve problems itself errors, include that failure rather than retrying the same detector. Open an Azure support request if available, or report the issue through the Static Web Apps GitHub repository; Microsoft lists both as support paths.^8^

    Provide:

    • Static Web App resource name and Azure region;
    • PR number and preview hostname;
    • production-versus-preview/provider result matrix;
    • UTC timestamps;
    • callback and /.auth/me status codes;
    • redacted HAR showing redirects and cookie attributes;
    • identity backend hostname, if shown;
    • request/correlation IDs;
    • confirmation that both providers fail only in preview;
    • screenshot or text of the diagnostics error.

    Do not include cookie values, authorization codes, access tokens, tenant identifiers, or other secrets.


    References

    1. Accessing user information in Azure Static Web Apps
    2. Authenticate and authorize Static Web Apps | Microsoft Learn
    3. Quotas in Azure Static Web Apps
    4. Preview environments in Azure Static Web Apps
    5. Custom authentication in Azure Static Web Apps
    6. Using /.auth/ behind Azure Front Door - Microsoft Q&A
    7. We are having some issues with the built in auth for static web apps - it only affects apps deployed in the last 48 hours - Microsoft Q&A
    8. Azure Static Web Apps Frequently Asked Questions
    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.