Lewee.Auth.Application 0.40.3

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

Lewee.Auth.Application

Application-layer services for provisioning users from external identity providers and authorizing MediatR commands/queries against tenant-role checks, with a built-in bypass for site administrators.

Features

  • Validates external user identifiers
  • Creates users without requiring tenant membership
  • Treats repeated provisioning requests as idempotent
  • Publishes and handles user domain events through MediatR
  • Maintains a per-tenant role lookup read model, kept in sync via domain event handlers
  • Restricts commands/queries to callers holding a tenant role via ITenantRoleRequest, with site administrators always allowed through
  • Caches user lookups performed during authorization to avoid a database round trip on every request
  • Provides dependency-injection registration for the auth application layer, and separately, for authorization

Dependencies

Configuration

Register the command handlers, validators, and domain event handlers:

using Lewee.Auth.Application;

services.AddLeweeAuthApplication();

The host must also register an IRepository<User> implementation. The Lewee.Auth.Infrastructure.Data package supplies the corresponding AuthDbContext.

Authorization is opt-in and registered separately, since not every consumer requires it:

services.AddLeweeApplicationAuth();

This registers TenantLoggingBehavior and TenantRoleAuthorizationBehavior as MediatR pipeline behaviors, in addition to the baseline behaviors registered by Lewee.Application.ApplicationConfiguration.AddPipelineBehaviors. It also registers an IMemoryCache and decorates the registered IRepository<User> with CachedUserRepository, so TenantRoleAuthorizationBehavior does not add a database round trip to every authorized request.

Usage

Dispatch CreateUserCommand with the stable subject identifier supplied by the external identity provider:

var result = await mediator.Send(
    new CreateUserCommand(externalUserId),
    cancellationToken);

The command validates the identifier against User.FieldLengths.ExternalId, returns success when the user already exists, and creates a new user with no tenant memberships otherwise. Tenant assignment remains a separate domain operation.

Authorization

Restrict a command or query to callers holding one of a set of tenant roles by implementing ITenantRoleRequest:

public sealed record AssignRoleCommand(Guid TenantId, Guid RoleId) : ICommand, ITenantRoleRequest
{
    public IReadOnlyCollection<string> Roles => ["MANAGER"];
}

TenantRoleAuthorizationBehavior resolves the caller, short-circuits with ResultStatus.Unauthenticated when no caller is resolved, and otherwise looks up the caller's User. When User.IsSiteAdministrator is true, the tenant/role check is bypassed entirely - a site administrator has super-user access to every tenant. Otherwise, the behavior short-circuits with ResultStatus.Unauthorized unless the caller is a member of request.TenantId and holds at least one of Roles for that tenant. The membership/role check is served by TenantMembershipRolesQueryProjection, a read model kept in sync by TenantAuthorizationQueryProjectionHandler reacting to membership/role domain events, avoiding a per-request join.

Requests that do not implement ITenantRoleRequest are unaffected by this behavior.

Main Types

Type Purpose
AuthApplicationConfiguration Registers auth application services (handlers, validators, event handlers)
ApplicationAuthConfiguration Registers the opt-in authorization pipeline behaviors and user repository cache
CreateUserCommand Idempotently provisions a user from an external identity
UserCreatedEventHandler Handles user-created domain notifications
UserDto Represents user data returned by application operations
ITenantRoleRequest Marker interface restricting a command/query to callers holding a tenant role
TenantRoleAuthorizationBehavior Pipeline behavior authorizing ITenantRoleRequests, with a site-administrator bypass
TenantLoggingBehavior Pipeline behavior adding the tenant ID to the logging scope of ITenantRequests
TenantMembershipRolesQueryProjection Read model of a user's tenant membership/roles
TenantAuthorizationQueryProjectionHandler Keeps the projection in sync with membership/role domain events
CachedUserRepository Decorates IRepository<User> with an in-memory cache of user lookups
Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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 Lewee.Auth.Application:

Package Downloads
Lewee.Auth.Api

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.40.3 50 11/22/2026