Search code examples
blazor-webassembly.net-5

Blazor WebAssembly Oidc Authentication works fine locally, but on Azure Static Web Apps has 404 on authentication/login-callback


I have a Blazor .Net5 WebAssembly that uses Auth0 OIDC authentication. I setup the authentication following these instructions: https://auth0.com/blog/securing-blazor-webassembly-apps/

Following those instructions I was able to develop my app locally and get it working with Auth0 authentication. However, when I deploy the app using Azure Static Web Apps the authentication is no longer functional. Looking in the developer tools of Chrome I can see that it successfully (302) calls my authorization endpoint:

https://login.mysite.com/authorize?clientid=*****...  (302)

The next url is the callback to my site, which fails with a 404:

https://myapp.mysite.com/authentication/login-callback?code=***... (404)

I do have the following in my index.html:

<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>

Any idea of what I can do to fix this?


Solution

  • I added a routes.json file to wwwroot with the following to fix the issue.

    {
      "routes": [
        {
          "route": "/*",
          "serve": "/index.html",
          "statusCode": 200
        }
      ]
    }