Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Entra AD login not working in Blazor WASM standalone Docker app

$
0
0

I have a monorepo with several projects, including a .NET web API and a Blazor WASM standalone project. The project structure is as follows:

root  docker-compose.yaml  | packages     | api        files     | blazor        blazor.sln        | Client           Client.csproj           Dockerfile           nginx.conf

docker-compose.yaml:

version: "3.7"services:  blazor:    build:      context: ./packages/blazor/Client    depends_on:      - api    environment:      - ASPNETCORE_ENVIRONMENT=Development      - ApiSettings__BaseUrl=http://localhost:8081    ports:      - "8080:80"  api:    build:      context: ./packages/api    environment:      - ASPNETCORE_ENVIRONMENT=Development    ports:      - "8081:80"      - "8082:443"    expose:      - "80"

Dockerfile for Blazor app:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS buildWORKDIR /srcCOPY Client.csproj .RUN dotnet restore Client.csprojCOPY . .RUN dotnet build Client.csproj -c Release -o /app/buildFROM build AS publishRUN dotnet publish Client.csproj -c Release -o /app/publishFROM nginx:alpine AS finalWORKDIR /usr/share/nginx/htmlCOPY --from=publish /app/publish/wwwroot .COPY nginx.conf /etc/nginx/nginx.conf

And finally nginx.conf:

events { }http {   include mime.types;   types {      application/wasm;    }  server {     listen 80;     index index.html;     location / {        root /user/share/nginx/html;        try_files $uri $uri/ /index.html =404;     }  }}

The blazor app is configured to use Entra AD to login users in Program.cs:

builder.Services.AddMsalAuthentication(options =>{    builder.Configuration.Bind("AzureAd", options.ProviderOptions.Authentication);    options.ProviderOptions.DefaultAccessTokenScopes.Add(builder.Configuration["ApiSettings:Scope"]!);});

When running the API via docker-compose and the Blazor app directly from Rider, everything works smoothly. I have a login button which opens a standard login modal where the user enters their Microsoft credentials and logs in. However when I start both the API and the Blazor app via docker-compose as specified in the files above, nothing happens when I click the login button. The apps starts as they should, and the Blazor app opens on localhost:8080, but when I click the login button it seems like the login modal pops up for a millisecond and then nothing else happens. The console prints the following error, which I'm not sure if is relevant:

Source map error: Error: JSON.parse: unexpected character at line 1 column 1 of the JSON dataResource URL: http://localhost:8080/_framework/dotnet.runtime.8.0.4.riehddozk1.jsSource Map URL: dotnet.runtime.js.map

This error is not present when starting the app directly from Rider.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>