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
<PackageReference Include="Lewee.Auth.Application" Version="0.40.3" />
<PackageVersion Include="Lewee.Auth.Application" Version="0.40.3" />
<PackageReference Include="Lewee.Auth.Application" />
paket add Lewee.Auth.Application --version 0.40.3
#r "nuget: Lewee.Auth.Application, 0.40.3"
#:package Lewee.Auth.Application@0.40.3
#addin nuget:?package=Lewee.Auth.Application&version=0.40.3
#tool nuget:?package=Lewee.Auth.Application&version=0.40.3
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
- Lewee.Application for CQRS, validation, and pipeline behaviors
- Lewee.Auth.Domain for user aggregates and specifications
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Lewee.Application (>= 0.40.3)
- Lewee.Auth.Domain (>= 0.40.3)
- Microsoft.Extensions.Caching.Memory (>= 11.0.0)
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 | 53 | 11/22/2026 |