azure-active-directoryblazorblazor-server-sideblazor-webassemblyasp.net-core-hosted-services

Is there a way to Authenticate a user before downloading the client side Blazor app?


I am currently working on a Blazor web assembly project that is core hosted. The project is split up into three parts, Client, Server and Shared. The way I understand it is that when a user hits the web address they will download the client side package and run it on their web browser. I would like to know if there is a way to Authenticate a user before they download the client side package?

I have successfully implemented a login process on the client side using the microsoft documentation: Secure an ASP.NET Core Blazor WebAssembly hosted app with Azure Active Directory

but I would like to take it a step further and see if I can authenticate a user before downloading the client side package.

I have spent most of my time adding authentication code to Server.Startup.cs assuming that when a user navigates to my website they would make a request to the server for the client side package.

Has anyone tried doing anything like this? Thanks for any advice


Solution

  • I don't think this is possible per se. But you could try adding a Blazor Server app that is responsible for authentication (since it loads way faster), and then switch to the Wasm app using an approach similar to what's shown in this article:https://itnext.io/blazor-switching-server-and-webassembly-at-runtime-d65c25fd4d8