Zonit.Extensions.Auth 10.0.0-preview.9

This is a prerelease version of Zonit.Extensions.Auth.
dotnet add package Zonit.Extensions.Auth --version 10.0.0-preview.9
                    
NuGet\Install-Package Zonit.Extensions.Auth -Version 10.0.0-preview.9
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zonit.Extensions.Auth" Version="10.0.0-preview.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zonit.Extensions.Auth" Version="10.0.0-preview.9" />
                    
Directory.Packages.props
<PackageReference Include="Zonit.Extensions.Auth" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zonit.Extensions.Auth --version 10.0.0-preview.9
                    
#r "nuget: Zonit.Extensions.Auth, 10.0.0-preview.9"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zonit.Extensions.Auth@10.0.0-preview.9
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zonit.Extensions.Auth&version=10.0.0-preview.9&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Zonit.Extensions.Auth&version=10.0.0-preview.9&prerelease
                    
Install as a Cake Tool

Zonit.Extensions.Auth

Authentication / authorization plug-in for ASP.NET Core, integrated with the standard Microsoft authorization pipeline (AddAuthorization, [Authorize], IAuthorizationService, <AuthorizeView>) and extended with VO-typed permission and role attributes.

NuGet Downloads

dotnet add package Zonit.Extensions.Auth

What you get

  • A cookie-based authentication scheme "Zonit" that turns the Session cookie into a ClaimsPrincipal via IdentityClaimsBuilder.
  • [RequirePermission("orders.read")] and [RequireRole("admin")] — built on .NET 8+ IAuthorizationRequirementData, no manual policy registration in AddAuthorization.
  • Permission and Role value-object aware authorization handlers (with wildcards, e.g. orders.*).
  • IAuthenticatedProvider.Current returning a lightweight Identity VO (Id + Name + Roles + Permissions).
  • A scoped IAuthenticatedRepository that the SessionMiddleware populates once per request / circuit.
  • Cascading authentication state for Blazor.

Setup

// Program.cs
builder.Services.AddAuthExtension();

var app = builder.Build();
app.UseAuthExtension();   // UseAuthentication → UseAuthorization → SessionMiddleware

Implement IAuthSource in your app (translate the cookie value into an Identity):

internal sealed class MyDbSessionProvider(MyDb db) : IAuthSource
{
    public async Task<Identity> GetByTokenAsync(string token, CancellationToken ct)
    {
        var s = await db.Sessions.Include(x => x.User)
                                 .ThenInclude(u => u.Roles)
                                 .FirstOrDefaultAsync(x => x.Token == token, ct);

        if (s is null || s.ExpiresAt < DateTime.UtcNow) return Identity.Empty;

        return new Identity(
            id:           s.User.Id,
            name:         new Title(s.User.DisplayName),
            roles:        s.User.Roles.Select(r => new Role(r.Name)),
            permissions:  s.User.Permissions.Select(p => Permission.Create(p)));
    }
}
builder.Services.AddScoped<IAuthSource, MyDbSessionProvider>();

Declarative authorization

// Controllers
[RequirePermission("orders.write")]
public IActionResult Update(...) => ...;

// Minimal API
app.MapGet("/admin", () => "ok")
   .RequireAuthorization(new RequirePermissionAttribute("admin.*"));

// Razor / Blazor pages
@attribute [RequirePermission("orders.read")]

// Components
<AuthorizeView Policy="@(new RequirePermissionAttribute("orders.read").Policy)">
  <Authorized>...</Authorized>
  <NotAuthorized>403</NotAuthorized>
</AuthorizeView>

Wildcards: a user holding orders.* satisfies [RequirePermission("orders.read")] automatically — the comparison goes through Permission.Implies.

Reading the current identity

@inject IAuthenticatedProvider Auth

@if (Auth.IsAuthenticated)
{
    <p>Hello, @Auth.Current.Name</p>
}

Or via the standard AuthenticationStateProvider / [CascadingParameter] Task<AuthenticationState> — the same principal is built via IdentityClaimsBuilder, so cookie-based and circuit-based paths are 1:1.

Claim shape (for advanced consumers)

Claim type Source
ClaimTypes.NameIdentifier Identity.Id
ClaimTypes.Name Identity.Name (skipped when empty)
ClaimTypes.Role one per Identity.Roles
zonit:permission one per Identity.Permissions (literal token, wildcards preserved)

The permission claim type is a constant: IdentityClaimsBuilder.PermissionClaimType.

What this package does NOT do

  • It does not provide login UI, password hashing, MFA or session storage. Those are the consumer's concern. The package only exposes the contract (IAuthSource).
  • It does not check authorization itself in IWorkspaceProvider / ICatalogProvider. Those are pure tenant context — authorization is one place, not two.

License

MIT.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Zonit.Extensions.Auth:

Package Downloads
Zonit.Extensions.Website

ASP.NET Core and Blazor web extensions providing base components (PageBase, PageEditBase, PageViewBase), navigation services, breadcrumbs management, toast notifications, cookie handling, and data protection utilities for building modern web applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0-preview.9 48 5/16/2026
10.0.0-preview.6 47 5/15/2026
10.0.0-preview.2 67 5/12/2026