![]() |
VOOZH | about |
dotnet add package RCommon.Security --version 2.4.1
NuGet\Install-Package RCommon.Security -Version 2.4.1
<PackageReference Include="RCommon.Security" Version="2.4.1" />
<PackageVersion Include="RCommon.Security" Version="2.4.1" />Directory.Packages.props
<PackageReference Include="RCommon.Security" />Project file
paket add RCommon.Security --version 2.4.1
#r "nuget: RCommon.Security, 2.4.1"
#:package RCommon.Security@2.4.1
#addin nuget:?package=RCommon.Security&version=2.4.1Install as a Cake Addin
#tool nuget:?package=RCommon.Security&version=2.4.1Install as a Cake Tool
Provides claims-based security abstractions for RCommon, including current user and current client identity access built on top of ClaimsPrincipal, with configurable claim type mappings and multi-tenancy support.
ICurrentUser exposes the authenticated user's ID, tenant ID, roles, and claims without depending on a specific auth frameworkICurrentClient identifies the calling OAuth/API client from the client_id claimICurrentPrincipalAccessor provides the current principal with support for temporary principal replacement via scoped IDisposableCurrentPrincipalAccessorBase uses AsyncLocal<T> so overridden principals flow across async contextsClaimTypesConst allows customizing which claim URIs map to user ID, tenant ID, client ID, roles, etc.ITenantIdAccessor provides runtime access to the current tenant ID for repository filtering; ClaimsTenantIdAccessor resolves it from claims, NullTenantIdAccessor is the default no-opAuthorizationException with configurable severity, error codes, and fluent data attachmentAddRCommon() builder pattern for one-line DI registrationdotnet add package RCommon.Security
using RCommon;
using RCommon.Security.Users;
using RCommon.Security.Clients;
// Register security services in your DI setup
services.AddRCommon(config =>
{
config.WithClaimsAndPrincipalAccessor();
});
// Inject ICurrentUser or ICurrentClient in your services
public class TenantService
{
private readonly ICurrentUser _currentUser;
private readonly ICurrentClient _currentClient;
public TenantService(ICurrentUser currentUser, ICurrentClient currentClient)
{
_currentUser = currentUser;
_currentClient = currentClient;
}
public string GetTenantId()
{
if (!_currentUser.IsAuthenticated)
throw new UnauthorizedAccessException("User is not authenticated.");
return _currentUser.TenantId
?? throw new InvalidOperationException("No tenant claim found.");
}
public string GetClientId()
{
return _currentClient.Id
?? throw new InvalidOperationException("No client identity found.");
}
public bool IsInRole(string role)
{
return _currentUser.Roles.Contains(role);
}
}
ITenantIdAccessor provides runtime access to the current tenant ID. When WithClaimsAndPrincipalAccessor() is called, the ClaimsTenantIdAccessor is registered, which resolves the tenant ID from the authenticated user's claims:
using RCommon.Security.Claims;
// ITenantIdAccessor is used by repositories to automatically filter and stamp entities
public class TenantAwareService
{
private readonly ITenantIdAccessor _tenantIdAccessor;
public TenantAwareService(ITenantIdAccessor tenantIdAccessor)
{
_tenantIdAccessor = tenantIdAccessor;
}
public string? GetCurrentTenant()
{
return _tenantIdAccessor.GetTenantId();
}
}
The default NullTenantIdAccessor returns null, which causes all tenant filtering to be bypassed. This allows the application to operate without multitenancy configured.
// Override the default claim type URIs at startup if your identity provider uses custom claims
ClaimTypesConst.UserId = "sub";
ClaimTypesConst.TenantId = "tenant";
ClaimTypesConst.ClientId = "azp";
| Type | Description |
|---|---|
ICurrentUser |
Provides the authenticated user's ID, tenant ID, roles, and claim lookups |
CurrentUser |
Default implementation that reads from the current ClaimsPrincipal |
ICurrentClient |
Provides the authenticated client application's ID and authentication status |
CurrentClient |
Default implementation that reads the client_id claim from the principal |
ICurrentPrincipalAccessor |
Accesses the current ClaimsPrincipal and supports scoped replacement |
ThreadCurrentPrincipalAccessor |
Default accessor that reads from Thread.CurrentPrincipal |
CurrentPrincipalAccessorBase |
Abstract base using AsyncLocal<T> for async-safe principal overrides |
ClaimTypesConst |
Configurable constants for standard claim type URIs (user ID, role, tenant, etc.) |
AuthorizationException |
Exception for unauthorized requests with log level, error code, and fluent data API |
ClaimsIdentityExtensions |
Extension methods for extracting user/tenant/client IDs and managing claims |
ITenantIdAccessor |
Runtime accessor returning the current tenant ID (string?) for repository filtering |
ClaimsTenantIdAccessor |
Claims-based implementation resolving tenant ID from ICurrentPrincipalAccessor |
NullTenantIdAccessor |
Default no-op implementation returning null (tenant filtering bypassed) |
For full documentation, visit rcommon.com.
HttpContextCurrentPrincipalAccessorLicensed under the Apache License, Version 2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 2 NuGet packages that depend on RCommon.Security:
| Package | Downloads |
|---|---|
|
RCommon.Persistence
A cohesive set of infrastructure libraries for dotnet that utilizes abstractions for event handling, persistence, unit of work, mediator, distributed messaging, event bus, CQRS, email, and more |
|
|
RCommon.Web
A cohesive set of infrastructure libraries for dotnet that utilizes abstractions for event handling, persistence, unit of work, mediator, distributed messaging, event bus, CQRS, email, and more |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.1.0-alpha.3 | 112 | 5/18/2026 |
| 2.4.2-alpha.0.10 | 96 | 4/5/2026 |
| 2.4.2-alpha.0.9 | 85 | 3/26/2026 |
| 2.4.2-alpha.0.8 | 73 | 3/26/2026 |
| 2.4.2-alpha.0.7 | 71 | 3/26/2026 |
| 2.4.2-alpha.0.6 | 79 | 3/25/2026 |
| 2.4.2-alpha.0.5 | 77 | 3/24/2026 |
| 2.4.2-alpha.0.1 | 76 | 3/24/2026 |
| 2.4.1 | 311 | 2/18/2026 |
| 2.3.2-alpha.0.3 | 78 | 2/18/2026 |
| 2.3.2-alpha.0.2 | 69 | 2/18/2026 |
| 2.3.2-alpha.0.1 | 70 | 2/9/2026 |
| 2.3.1 | 125 | 2/5/2026 |
| 2.3.0 | 117 | 2/3/2026 |
| 2.2.2-alpha.0.1 | 412 | 12/11/2025 |
| 2.2.1-alpha.0.2 | 154 | 10/24/2025 |
| 2.2.1-alpha.0.1 | 147 | 10/24/2025 |
| 2.1.11-alpha.0.2 | 151 | 10/24/2025 |
| 2.1.11-alpha.0.1 | 121 | 7/18/2025 |
| 2.1.10 | 217 | 7/17/2025 |