How to fix the failing /.auth/login/aadb2c static web app endpoint?

Steffen Dyhr-Nielsen 1 Reputation point
2022-12-08T09:47:40.827+00:00

I have followed the Configure authentication in an Azure Static Web App by using Azure AD B2C documentation

Following step 4 I get the following error across browsers:

Refused to execute script from 'https://<domain>.azurestaticapps.net/.auth/login/aadb2c' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I have tried to add the "Content-Type": "application/javascript" header via staticwebapp.config.json with no luck.

Here is my staticwebapp.config.json (after the headers modification):

{  
  "routes": [  
    {  
      "route": "/.auth/login/aadb2c",  
      "allowedRoles": [  
        "authenticated",  
        "anonymous"  
      ],  
      "headers": {  
        "Content-Type": "application/javascript"  
      }  
    },  
    {  
      "route": "/*",  
      "allowedRoles": [  
        "authenticated"  
      ]  
    }  
  ],  
  "globalHeaders": {  
    "Content-Type": "application/javascript"  
  },  
  "responseOverrides": {  
    "401": {  
      "statusCode": 302,  
      "redirect": "/.auth/login/aadb2c"  
    }  
  },  
  "navigationFallback": {  
    "rewrite": "index.html",  
    "exclude": [  
      "/content/*.{png,jpg,gif}"  
    ]  
  },  
  "auth": {  
    "identityProviders": {  
      "customOpenIdConnectProviders": {  
        "aadb2c": {  
          "registration": {  
            "clientIdSettingName": "AADB2C_PROVIDER_CLIENT_ID",  
            "clientCredential": {  
              "clientSecretSettingName": "AADB2C_PROVIDER_CLIENT_SECRET"  
            },  
            "openIdConnectConfiguration": {  
              "wellKnownOpenIdConfiguration": "https://<domain>.onmicrosoft.com.b2clogin.com/<domain>.onmicrosoft.com.onmicrosoft.com/B2C_1_SignIn/v2.0/.well-known/openid-configuration"  
            }  
          },  
          "login": {  
            "nameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",  
            "scopes": [],  
            "loginParameterNames": []  
          }  
        }  
      }  
    }  
  }  
}  

I tried to remove the header stuff and the navigationFallback but then I simply get a 404 "not found".

So how do I log in to my static web app using B2C?

Microsoft Security | Microsoft Entra | Microsoft Entra External ID
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
1,178 questions
{count} votes

Your answer

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