Behrouzan.Auth 0.1.0-preview.1

This is a prerelease version of Behrouzan.Auth.
dotnet add package Behrouzan.Auth --version 0.1.0-preview.1
                    
NuGet\Install-Package Behrouzan.Auth -Version 0.1.0-preview.1
                    
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="Behrouzan.Auth" Version="0.1.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Behrouzan.Auth" Version="0.1.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Behrouzan.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 Behrouzan.Auth --version 0.1.0-preview.1
                    
#r "nuget: Behrouzan.Auth, 0.1.0-preview.1"
                    
#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 Behrouzan.Auth@0.1.0-preview.1
                    
#: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=Behrouzan.Auth&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Behrouzan.Auth&version=0.1.0-preview.1&prerelease
                    
Install as a Cake Tool

Behrouzan.Auth

Prepared for preview release 0.1.0-preview.1 under the MIT license:

dotnet add package Behrouzan.Auth --version 0.1.0-preview.1

The command becomes usable from nuget.org after this version is published; this README does not assert that the push has already occurred.

Behrouzan.Auth is the framework-neutral core package. It provides permission-definition and role-grant abstractions, refresh-token abstractions and lifecycle management, option types, and dependency-injection registrations.

It does not configure ASP.NET Core authentication, issue or validate JWTs, persist refresh tokens, or supply an Identity/EF Core implementation. The application must register implementations of the storage interfaces it uses, such as IRefreshTokenStore<TKey>, IPermissionGrantStore<TKey>, and IRolePermissionGrantStore<TKey>.

Relationship to the other packages

This is the base package. Behrouzan.Auth.AspNetCore and Behrouzan.Auth.EntityFrameworkCore both depend on it. Neither package is required when an application supplies its own ASP.NET Core integration or persistence implementation.

Minimal registration

using Behrouzan.Auth.Authentication;
using Behrouzan.Auth.DependencyInjection;
using Behrouzan.Auth.Permissions;

builder.Services.AddBehrouzanAuth();
builder.Services.AddRefreshTokens(options =>
    options.Lifetime = TimeSpan.FromDays(14));

// Application-provided persistence implementations.
builder.Services.AddScoped<IRefreshTokenStore<Guid>, ApplicationRefreshTokenStore>();
builder.Services.AddScoped<IPermissionGrantStore<Guid>, ApplicationPermissionGrantStore>();
builder.Services.AddScoped<IRolePermissionGrantStore<Guid>, ApplicationRolePermissionGrantStore>();

AddRefreshTokens validates that the lifetime is positive and registers IRefreshTokenManager<TKey>. The example's three Application...Store types are application implementations of the corresponding interfaces; the core package does not include them.

Permission and refresh-token use

After an application defines and registers its permission provider, it can manage a role's defined permissions and check a user's effective permissions:

var grant = await rolePermissionManager.GrantAsync(
    administratorRoleId,
    "Products.Create",
    cancellationToken);

if (!grant.IsSuccess)
    return grant.ErrorCode; // UnknownPermission when the name was not defined.

var canCreate = await permissionChecker.IsGrantedAsync(
    userId,
    "Products.Create",
    cancellationToken);

RolePermissionManager<TKey> stores grants against roles. Whether canCreate is true depends on the application's IPermissionGrantStore<TKey> implementation; the EF Core implementation derives it from the user's Identity role memberships.

The refresh-token manager returns result objects rather than throwing for ordinary invalid-token outcomes:

var created = await refreshTokenManager.CreateAsync(userId, cancellationToken);
if (created.IsSuccess)
{
    var renewal = await refreshTokenManager.RefreshAsync(
        created.Token!, cancellationToken);

    // A failed renewal reports InvalidToken, Expired, Revoked,
    // ReuseDetected, or ConcurrencyConflict through ErrorCode.
}

After registration, an application can inject IRefreshTokenManager<Guid> and use CreateAsync, ValidateAsync, RefreshAsync, RevokeAsync, and RevokeAllAsync. Treat a raw refresh token as a credential: return it only to its owner and never persist it in plaintext.

For permission definitions, role-grant management, and user permission checks, see the Permissions guide. Permissions are granted to roles; direct user permission grants are not provided.

Important limits

  • Revoking a refresh token does not immediately invalidate an already-issued access JWT.
  • RevokeAllAsync revokes active refresh tokens for a trusted user ID; callers must derive that ID from an authenticated identity, not request input.
  • Security-stamp changes do not automatically revoke refresh tokens.
  • Concurrency behavior is determined in part by the storage implementation and database provider.

The repository's detailed guidance is available at:

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 (2)

Showing the top 2 NuGet packages that depend on Behrouzan.Auth:

Package Downloads
Behrouzan.Auth.EntityFrameworkCore

Entity Framework Core storage and model configuration for Behrouzan.Auth permissions and refresh tokens.

Behrouzan.Auth.AspNetCore

ASP.NET Core and Identity integration for Behrouzan.Auth permissions, password sign-in, and token authentication orchestration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-preview.1 65 9/25/2026