Winche.Sentinel
1.0.0
See the version list below for details.
dotnet add package Winche.Sentinel --version 1.0.0
NuGet\Install-Package Winche.Sentinel -Version 1.0.0
<PackageReference Include="Winche.Sentinel" Version="1.0.0" />
<PackageVersion Include="Winche.Sentinel" Version="1.0.0" />
<PackageReference Include="Winche.Sentinel" />
paket add Winche.Sentinel --version 1.0.0
#r "nuget: Winche.Sentinel, 1.0.0"
#:package Winche.Sentinel@1.0.0
#addin nuget:?package=Winche.Sentinel&version=1.0.0
#tool nuget:?package=Winche.Sentinel&version=1.0.0
Winche.Sentinel
Path-based authorization middleware for .NET. Define access rules per resource type using path patterns, and evaluate them against caller claims and operations.
Install
dotnet add package Winche.Sentinel
Quick Start
services.AddWincheSentinel<Document>(c =>
{
c.AddResourceObjectAccessor<DocumentAccessor>();
c.AddCallerContextAccessor<HttpContextClaimsAccessor>();
c.AddResourceAccessRule(new DocumentRule("/docs/{id}", [AccessOperation.Read, AccessOperation.Write]));
});
Inject IAccessRuleEvaluator<Document> and call it before performing the operation:
// throws AccessDeniedException or NoRulesMatchedException on failure
await evaluator.EvaluateAsync(AccessOperation.Read, "/docs/42");
How It Works
- The evaluator matches the incoming path against each registered rule's path pattern.
- The first matching rule's
EvaluateAsyncis called with anAccessContext<TResource>. - Return
trueto grant access,falseto deny (AccessDeniedExceptionis thrown). - If no rule matches,
NoRulesMatchedExceptionis thrown.
Path Patterns
| Pattern | Matches |
|---|---|
/docs/42 |
Exact match |
/docs/{id} |
Any single segment; captured as Params["id"] |
/docs/* |
Any single segment (unnamed) |
/docs/** |
Zero or more remaining segments; captured as Params["**"] |
** must be the last segment in the pattern.
Implementing a Rule
using WincheSentinel.Interfaces;
using WincheSentinel.Models;
public class DocumentRule(string path, IEnumerable<AccessOperation> ops) : IResourceAccessRule<Document>
{
public string Path => path;
public IReadOnlySet<AccessOperation> Operations => new HashSet<AccessOperation>(ops);
public async Task<bool> EvaluateAsync(AccessContext<Document> context, CancellationToken ct)
{
var doc = await context.GetResourceAsync(ct);
var userId = context.Claims["sub"] as string;
return doc?.OwnerId == userId;
}
}
AccessContext
| Member | Description |
|---|---|
Operation |
Read, Write, or Delete |
Path |
The path being accessed |
Params |
Path parameters extracted from the pattern |
Claims |
Caller claims from ICallerContextAccessor |
GetResourceAsync |
Lazy loader for the resource object |
Data |
Optional extra data passed to EvaluateAsync |
Multiple Resource Types
Call AddWincheSentinel<T>() once per resource type — each gets its own isolated rule set and evaluator.
License
Elastic License 2.0
| Product | Versions 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. |
-
net10.0
- Microsoft.Extensions.Options (>= 10.0.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Winche.Sentinel:
| Package | Downloads |
|---|---|
|
Winche.Sentinel.AspNetCore
Path-based authorization middleware for .NET. Define access rules per resource type using path patterns, and evaluate them against caller claims and operations. |
GitHub repositories
This package is not used by any popular GitHub repositories.