Hi!
I’ve developed a “pure” Blazor WebAssembly app (without Blazor Server) and an MVC API. The WebAssembly app should authenticate with Auth0 and send HTTP client requests to the external API, passing along Auth0’s access token and user roles.
I don’t understand how to do this without a Blazor Server, or even if it’s possible.
Yes, it is absolutely possible to build a “pure” Blazor WebAssembly app that authenticates with Auth0 and securely calls an external MVC API. This is a very common and recommended architecture. You do not need Blazor Server to achieve this.
The key is to handle the authentication flow entirely on the client side and then configure your API to validate the tokens that the client sends.
Thank you for your reply!
Could you please share an example code of the http client configuration in the program.cs of the WebAssembly app?
I’ve tried the following but it doesn’t work as expected, since the token doesn’t arrive to the API.
builder.Services.AddHttpClient("ServerAPI",
client => client.BaseAddress = new Uri("UriApi"))
.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>();
builder.Services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>()
.CreateClient("ServerAPI"));