x-ms-client-principal header not included in request from SWA to connected Container App API

Austin James 0 Reputation points
2024-03-28T17:46:58.43+00:00

We are experiencing an issue with our SWA where the x-ms-client-principal header is intermittently not included in requests to APIs host on a connected Azure Container App, which is causing intermittent 401 responses which are incorrect. We are following the steps laid out in the Azure documentation for accessing user information for SWAs: https://learn.microsoft.com/en-us/azure/static-web-apps/user-information?tabs=javascript and call the "/.auth/me" on the front end via a fetch implementation laid out in Vue documentation: https://vuejs.org/guide/reusability/composables.html#async-state-example.

Is there any way to protect against this issue?

This issue has also been previously raised on GitHub at: https://github.com/Azure/static-web-apps/issues/1053#issuecomment-1845878160

Azure Container Apps
Azure Container Apps

An Azure service that provides a general-purpose, serverless container platform.

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. Bryan Trach 17,842 Reputation points Microsoft Employee Moderator
    2024-04-02T01:39:22.99+00:00

    @Austin James Have you been able to implement the suggested workaround? This may help to provide you relief until we receive an answer from the product group.

    There is a workaround for this:

    • adding an "allowedRoles" with route "*"
    • adding all non-secured routes (a long list) in front of it

    Here is an example for this:

    {
      "navigationFallback": {
        "rewrite": "/api/render"
      },
      "routes": [
        {
          "route": "/manifest.json"
        },
        {
          "route": "/service-worker.js"
        },
        {
          "route": "/robots.txt"
        },
        {
          "route": "/static/*"
        },
        ...
        {
          "route": "*",
          "allowedRoles": ["authenticated"]
        }
      ]
    }
    

    In the meantime, we have reached out to the product group for their input.

    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.