BytexDigital.Blazor.Server.Authentication
Authentication library for serversided Blazor
Install / Use
/learn @BytexDigital/BytexDigital.Blazor.Server.AuthenticationREADME
BytexDigital.Blazor.Server.Authentication
This library adds a simple way of being able to sign in, sign out and remember the signed in user (e.g. via cookies) directly from Blazor without the need of redirecting the user to Razor pages.
Existing Blazor components such as AuthorizeView will continue to work as expected.
:warning: This library is meant only for server-sided Blazor.
Download
:arrow_forward: BytexDigital.Blazor.Server.Authentication Nuget package
:arrow_forward: BytexDigital Blazor.Server.Authentication.Identity Nuget package
How to use?
1. Install BytexDigital.Blazor.Server.Authentication or BytexDigital.Blazor.Server.Authentication.Identity
2. Register the necessary services
Make sure to register the services after other calls to add Authentication services.
Required in all cases
services.AddHttpContextAccessor();
With Identity
services
.AddAuthenticationService()
.AddCookiePrincipalStorage()
.AddIdentityPrincipalProvider<ApplicationUser>();
Without Identity
services
.AddAuthenticationService()
.AddCookiePrincipalStorage()
.AddPrincipalProvider<ImplementationOfIPrincipalProvider>();
3. Add the Javascript to your _Host.cshtml
<script src="/_content/BytexDigital.Blazor.Server.Authentication/bundle.js"></script>
Edit your App.razor to wrap your content in a CascadingAuthenticationProvider
<BytexDigital.Blazor.Server.Authentication.CascadingAuthenticationProvider>
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<NotFound></NotFound>
</LayoutView>
</NotFound>
</Router>
</BytexDigital.Blazor.Server.Authentication.CascadingAuthenticationProvider>
Sign in and sign out
Use IServerAuthenticationService.SignInAsAsync and IServerAuthenticationService.SignOutAsync to change the signed in user.
Reloading the page is not necessary. You can use IServerAuthenticationService.GetSignedInIdOrDefault and IServerAuthenticationService.IsSignedIn to get information about the current authentication status.
Questions
What is the IPrincipalProvider?
The IPrincipalProvider is used to convert a user id to a ClaimsPrincipal object. The included IdentityPrincipalProvider will convert the user id to a principal using a UserStore<TUser>.
Related Skills
node-connect
351.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
Languages
Security Score
Audited on Feb 23, 2026
