This sample demonstrates .NET MAUI Blazor Hybrid and Web App that shares common UI and authentication. The sample uses ASP.NET Core Identity local accounts, but you can use this pattern for any authentication provider from a MAUI Blazor Hybrid client.
The sample:
- Sets up the UI to show or hide pages based on user authentication.
- Sets up ASP.NET Identity endpoints for remote clients.
- Logs users in, logs users out, and refreshes tokens from the MAUI client.
- Saves and retrieves tokens in secure device storage.
- Calls a secure endpoint (
/api/weather) from the client.
For more information, see .NET MAUI Blazor Hybrid and Web App with ASP.NET Core Identity.
- Clone this repository or download a ZIP archive of the repository. For more information, see How to download a sample.
- Make sure you have .NET 9 and the MAUI workload installed.
- Open the solution in Visual Studio 2022 or VS Code with the .NET MAUI extension installed.
- Set the
MauiBlazorWebMAUI project as the startup project. In Visual Studio, right-click the project and select Set as Startup Project. - Start the
MauiBlazorWeb.Webproject without debugging. In Visual Studio, right-click on the project and select Debug > Start without Debugging. - Inspect the Identity endpoints by navigating to
https://localhost:7157/swaggerin a browser. - Navigate to
https://localhost:7157/account/registerto register a user in the Blazor Web App. Immediately after the user is registered, use the Click here to confirm your account link in the UI to confirm the user's email address because a real email sender isn't registered for account confirmation. - Start (
F5) theMauiBlazorWebMAUI project. You can set the debug target to either Windows or an Android emulator. - Notice you can only see the
HomeandLoginpages. - Log in with the user that you registered.
- Notice you can now see the shared
CounterandWeatherpages. - Log out and notice you can only see the
HomeandLoginpages again. - Navigate to
https://localhost:7157/and the web app behaves the same.