OrionLedger.AspNetCore
0.5.0
dotnet add package OrionLedger.AspNetCore --version 0.5.0
NuGet\Install-Package OrionLedger.AspNetCore -Version 0.5.0
<PackageReference Include="OrionLedger.AspNetCore" Version="0.5.0" />
<PackageVersion Include="OrionLedger.AspNetCore" Version="0.5.0" />
<PackageReference Include="OrionLedger.AspNetCore" />
paket add OrionLedger.AspNetCore --version 0.5.0
#r "nuget: OrionLedger.AspNetCore, 0.5.0"
#:package OrionLedger.AspNetCore@0.5.0
#addin nuget:?package=OrionLedger.AspNetCore&version=0.5.0
#tool nuget:?package=OrionLedger.AspNetCore&version=0.5.0
<p align="center"> <img src="https://raw.githubusercontent.com/tunahanaliozturk/OrionLedger/main/docs/logo.png" alt="OrionLedger" width="150" /> </p>
OrionLedger.AspNetCore
ASP.NET Core authentication for OrionLedger. An
authentication handler reads the API key from a configurable request header, verifies it through
OrionLedger (hash lookup, revoked / expired / retired checks, and the last-used stamp), and on
success establishes a ClaimsPrincipal carrying the key's subject, id, and scopes. Scopes are
projected into claims so standard [Authorize(Policy = ...)] authorization gates an endpoint on a
scope without the endpoint re-checking it.
dotnet add package OrionLedger.AspNetCore
Quick start
using Moongazing.OrionLedger;
using Moongazing.OrionLedger.AspNetCore;
using Moongazing.OrionLedger.AspNetCore.Authorization;
var builder = WebApplication.CreateBuilder(args);
// The key service the handler verifies against (in-memory store by default; swap in the
// EF Core store for persistence).
builder.Services.AddOrionLedger();
builder.Services
.AddAuthentication(ApiKeyAuthenticationOptions.DefaultScheme)
.AddOrionLedgerApiKey(options =>
{
options.HeaderName = "X-Api-Key"; // the default
});
builder.Services.AddAuthorization(options =>
{
// A named policy that requires the "orders:read" scope.
options.AddApiKeyScopePolicy("orders:read", "orders:read");
});
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/orders", () => "ok")
.RequireAuthorization("orders:read");
app.Run();
How it maps
- The header value is used verbatim as the presented token (no
Bearerprefix is stripped). - A
Validverification yields a principal with: the key id (orionledger:key-idby default), the subject asClaimTypes.NameIdentifierand the identity name (when the key has a subject), and onescopeclaim per granted scope. - Any other status (revoked, expired, retired, unknown, malformed) fails authentication with no
principal, so the request is unauthenticated and the framework returns
401. - A missing header produces
NoResult, leaving other schemes and anonymous endpoints undisturbed.
Requiring scopes
Inline on an endpoint or in a named policy:
builder.Services.AddAuthorization(options =>
{
// Any one of the listed scopes.
options.AddPolicy("reporting", p => p.RequireApiKeyScope("reports:read", "reports:write"));
// Require all listed scopes.
options.AddPolicy("admin", p => p.RequireApiKeyScope(
ApiKeyAuthenticationOptions.DefaultScopeClaimType, requireAll: true, "keys:admin", "keys:write"));
});
The claim type used for scopes, the subject, and the key id are all configurable on
ApiKeyAuthenticationOptions.
See the project repository for the core key lifecycle API, the EF Core store, and the full design spec.
| Product | Versions 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 is compatible. 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 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
- OrionLedger (>= 0.5.0)
-
net8.0
- OrionLedger (>= 0.5.0)
-
net9.0
- OrionLedger (>= 0.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.