saiwolf / BlazorADAuthExample

5 stars 1 forks source link

Blazor .NET 8 with Identity & AD Integration

This is a Blazor .NET 8 application leverage Microsoft ASP.NET Core Identity with some customizations to use on-prem Active Directory to do password checking.

Since this project leverages Identity, a DB is created to store user information. Since AD is used for password checking, the password is never stored in the DB. Only user information pertinent to the app is stored.

TODO (As of 8/26/2024)

Requirements

Considerations

First Time Setup

If you're using User Secrets

And you really should be!

  • Regenerate the user secrets via dotnet user-secrets init. Visual Studio users can right click on the project and select 'Manage User Secrets'. Otherwise, look in %APPDATA%\Microsoft\User Secrets in Windows.
  • Copy the contents of appsettings.Example.json into the user secrets file and edit accordingly.

If you're not using User Secrets

Run the DB Seed routine

Running the app

It is highly recommended to use Visual Studio, Rider, or VS Code for debugging of the app.

  • The app can be run from the command line with dotnet run in the top project directory.

What If I Want Interactivity Globally?

One major caveat of Interactive Render Modes in Blazor is the lack of access to HttpContext. Server mode runs over a SignalR circuit, and WASM runs in the client. Because of this, Identity uses Static Server Rendering with its razor components and code.

If you want to enable Interactivity on a per-component basis, then no changes are required. Just make sure to not add any @rendermode to any Identity pages under /Component/Accounts/Pages.

However, if you want to enable Interactivity globally, then some changes are required:

Note: Any page starting with /account will be rendered as SSR with this method, as these pages rely on access to HttpContext which is not present otherwise.