Perago.SharedKernel.Authorization
1.0.98
dotnet add package Perago.SharedKernel.Authorization --version 1.0.98
NuGet\Install-Package Perago.SharedKernel.Authorization -Version 1.0.98
<PackageReference Include="Perago.SharedKernel.Authorization" Version="1.0.98" />
<PackageVersion Include="Perago.SharedKernel.Authorization" Version="1.0.98" />
<PackageReference Include="Perago.SharedKernel.Authorization" />
paket add Perago.SharedKernel.Authorization --version 1.0.98
#r "nuget: Perago.SharedKernel.Authorization, 1.0.98"
#:package Perago.SharedKernel.Authorization@1.0.98
#addin nuget:?package=Perago.SharedKernel.Authorization&version=1.0.98
#tool nuget:?package=Perago.SharedKernel.Authorization&version=1.0.98
Perago.SharedKernel.Authorization
API authentication, HMAC request signing, opt-in API keys, policy authorization, session revocation, request context, service defaults, health checks, security hardening, rate limiting, OpenAPI conventions, configuration validation, OpenTelemetry, and ASP.NET Core observability middleware for Perago services.
Installation
dotnet add package Perago.SharedKernel.Authorization
Getting Started
JWT Authentication Setup
// appsettings.json
{
"AuthApiConfiguration": {
"RequireHttpsMetadata": false,
"Resilience": {
"Enabled": true,
"BackchannelTimeout": "00:00:05",
"ExceptionsAllowedBeforeBreaking": 3,
"CircuitBreakDuration": "00:00:30"
},
"Resources": [
{
"Key": "BackOffice1",
"IdentityServerBaseUrl": "http://identity-server:9900/auth",
"OidcApiName": "my_api"
}
]
}
}
// Program.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddApiAuthentication(Configuration);
}
public void Configure(IApplicationBuilder app)
{
app.UseApiAuthentication();
app.UseAuthorization();
}
When Resilience.Enabled is true (default), each configured authority gets its own OIDC backchannel timeout and circuit breaker. After repeated metadata/JWKS failures, subsequent requests fail fast with 401 instead of waiting on every HTTP call. Retries are intentionally omitted on the authentication hot path.
When multiple Resources entries are configured, AddApiAuthentication registers an issuer-based policy scheme (PeragoAuth) so each request forwards to the JWT scheme that matches the token iss claim instead of trying every authority sequentially.
JWT metadata HTTPS (H1)
AuthApiConfiguration:RequireHttpsMetadata defaults to false so existing HTTP authority URLs keep working until you opt in. When true, JWT bearer metadata and JWKS must be retrieved over HTTPS (authority URL must use https://, or set per-resource RequireHttpsMetadata to false for trusted HTTP deployments).
Startup validation (ValidateAuthApi) fails only when RequireHttpsMetadata is enabled for a resource but IdentityServerBaseUrl is not https://.
HMAC Authentication Setup
HMAC adds an extra security layer for POST/PUT/DELETE requests. Register feature management first. Preferred settings live under FeatureManagement:platform:hmacAuth. Legacy top-level HmacAuth is still used when that feature section is not configured.
services.AddPeragoFeatureManagement(Configuration);
services.AddHmacAuth(Configuration);
app.UseMiddleware<HmacPostRequestMiddleware>();
"FeatureManagement": {
"RefreshIntervalSeconds": 30,
"FailOpen": false,
"platform": {
"hmacAuth": {
"enabled": true,
"sharedSecret": "your-secure-secret-key",
"allowedClockSkewSeconds": 60,
"nonceTtlSeconds": 300,
"nonceStoreProvider": "Memory",
"skipPaths": ["/api/public/health"],
"skipPathPrefixes": ["/api/public"]
}
}
}
Skip HMAC for Specific Endpoints
[HmacAuthSkip]
[HttpPost("api/public/endpoint")]
public IActionResult PublicEndpoint() => Ok();
API Key Authentication Setup
Opt-in middleware for machine-to-machine endpoints. JWT routes stay unchanged unless marked with [PeragoRequireApiKey].
// appsettings.json
{
"ErpAPIConfig": {
"APIKey": "from-env-or-secret-store"
}
}
// Program.cs / Program.cs
using Perago.SharedKernel.Authorization.ApiKey;
public void ConfigureServices(IServiceCollection services)
{
services.AddPeragoApiKey(Configuration);
}
public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseAuthorization();
app.UsePeragoApiKey();
app.MapControllers();
}
[PeragoRequireApiKey]
[HttpGet("api/internal/ping")]
public IActionResult Ping() => Ok();
Callers pass ?apiKey=... or header X-API-Key (prefer the header in production). Invalid or missing keys return 401 with no body. Hosts fail to start if marked endpoints exist without UsePeragoApiKey(). Request logs redact apiKey / api_key and any overridden QueryParameterName. See docs/API_KEY.md for HMAC interaction notes.
Session Revocation
Optional Redis check against JWT session (not sid). STS writes revoked:session:{guid}; matching requests return 401.
services.AddPeragoSessionRevocation(Configuration);
app.UsePeragoSessionRevocation();
See docs/SESSION_REVOCATION.md.
Observability Setup
Correlation IDs, request logging, exception logging, Serilog host enrichment, and optional OpenTelemetry traces/metrics export. See docs/OBSERVABILITY.md in the package for full details.
using Perago.SharedKernel.Authorization.Observability;
using Perago.SharedKernel.Authorization.OpenTelemetry;
// Program.cs / Program.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddPeragoObservability();
services.AddPeragoOpenTelemetry(Configuration, Environment, settings =>
{
settings.DefaultServiceName = "MyServiceName";
});
}
public void Configure(IApplicationBuilder app)
{
app.UsePeragoObservability(); // Exception -> Correlation -> Request logging
}
builder.Host.UsePeragoSerilog("MyServiceName");
Service Defaults
Use the service defaults when a service wants the recommended shared-kernel API stack with one registration point.
public void ConfigureServices(IServiceCollection services)
{
services.AddPeragoServiceDefaults(Configuration, options =>
{
options.EnableConfigurationValidation = true;
options.EnableExceptionHandling = true;
options.EnableRequestContext = true;
options.EnableRateLimiting = true;
options.EnableOpenApiConventions = true;
options.EnableOpenTelemetry = true;
options.EnableSessionRevocation = true;
});
}
public void Configure(IApplicationBuilder app)
{
app.UsePeragoServiceDefaults();
}
PeragoServiceDefaultsOptions flags default to false. Opt in explicitly. Environment-specific overrides still apply for Development and Test after consumer configuration runs.
Request Context and Correlation
Register request-context helpers to expose user, organization, tenant, application, request, and correlation metadata through one accessor. The same metadata can be propagated to outgoing HTTP calls and integration messages.
services.AddPeragoRequestContext();
app.UsePeragoRequestContext();
Rate Limiting
Register named policies globally, then apply them per action or controller.
services.AddPeragoRateLimiting(options =>
{
options.AddFixedWindowPolicy("commands", permitLimit: 20, window: TimeSpan.FromMinutes(1));
});
[PeragoRateLimiter("commands")]
public IActionResult CreateOrder() => Ok();
Configuration Validation
Startup validation fails fast when shared-kernel settings are missing or unsafe. Diagnostics are aggregated and redact secret values.
services.AddPeragoConfigurationValidation(Configuration, options =>
{
options.EnvironmentName = "Production";
options.RequireRabbitMq = true;
options.RequireDatabase = true;
});
Documentation
Package docs include setup and migration details:
| Topic | Packaged doc |
|---|---|
| Service defaults | docs/SERVICE_DEFAULTS.md |
| Observability and correlation | docs/OBSERVABILITY.md |
| OpenTelemetry / OTLP | docs/TELEMETRY.md |
| Request and tenant context | docs/REQUEST_CONTEXT.md |
| Multi-tenancy | docs/MULTI_TENANCY.md |
| Health checks | docs/HEALTH_CHECKS.md |
| Exception handling | docs/EXCEPTION_HANDLING.md |
| Authorization policies | docs/AUTHORIZATION_POLICIES.md |
| Resilience | docs/RESILIENCE.md |
| Idempotency | docs/IDEMPOTENCY.md |
| Security hardening | docs/SECURITY_HARDENING.md |
| Rate limiting and store choices | docs/RATE_LIMITING.md |
| Session revocation | docs/SESSION_REVOCATION.md |
| OpenAPI conventions | docs/OPENAPI_CONVENTIONS.md |
| API key authentication | docs/API_KEY.md |
| Configuration validation | docs/CONFIGURATION_VALIDATION.md |
| Migration notes | docs/OBSOLETE_API_MIGRATION_NOTES.md |
HMAC Headers
| Header | Description |
|---|---|
X-Hmac-Timestamp |
Unix timestamp (seconds) in UTC |
X-Hmac-Nonce |
Unique random value (e.g., UUID) |
X-Hmac-Signature |
Base64-encoded HMAC-SHA256 signature |
Dependencies
Versions are managed centrally in this repository (Directory.Packages.props):
- Microsoft.AspNetCore.Authentication.JwtBearer (10.0.12)
- Microsoft.EntityFrameworkCore (10.0.12)
- Npgsql / Npgsql.EntityFrameworkCore.PostgreSQL / Npgsql.OpenTelemetry (10.0.3)
- Audit.EntityFramework.Core (32.3.1)
- MassTransit (7.3.0)
- Newtonsoft.Json (13.0.4)
- Polly (8.8.0)
- Serilog.AspNetCore (10.0.0)
- Serilog.Exceptions (8.4.0)
- OpenTelemetry.* (1.19.0); Redis instrumentation is
1.19.0-beta.1 - StackExchange.Redis (2.13.17)
- Swashbuckle.AspNetCore (10.2.3)
Target Frameworks
- net10.0
License
MIT
| 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
- Audit.EntityFramework.Core (>= 32.3.1)
- Autofac (>= 8.4.0)
- Dapper (>= 2.1.86)
- FluentValidation (>= 12.1.1)
- HtmlSanitizer (>= 9.2.1039)
- MailKit (>= 4.18.0)
- MassTransit (>= 7.3.0)
- MediatR (>= 12.5.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 10.0.12)
- Microsoft.EntityFrameworkCore (>= 10.0.12)
- Microsoft.FeatureManagement (>= 2.6.1)
- MimeKit (>= 4.18.0)
- Newtonsoft.Json (>= 13.0.4)
- Npgsql (>= 10.0.3)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.3)
- Npgsql.OpenTelemetry (>= 10.0.3)
- OpenTelemetry.Exporter.Console (>= 1.19.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.19.0)
- OpenTelemetry.Extensions.Hosting (>= 1.19.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.19.0)
- OpenTelemetry.Instrumentation.Http (>= 1.19.0)
- OpenTelemetry.Instrumentation.StackExchangeRedis (>= 1.19.0-beta.1)
- Perago.SharedKernel.Abstraction.Application (>= 1.0.98)
- Perago.SharedKernel.Abstraction.Domain (>= 1.0.98)
- Perago.SharedKernel.Abstraction.Infrastructure (>= 1.0.98)
- Perago.SharedKernel.EventBus (>= 1.0.98)
- Perago.SharedKernel.EventBusRabbitMQ (>= 1.0.98)
- Perago.SharedKernel.Notification (>= 1.0.98)
- Polly (>= 8.8.0)
- RabbitMQ.Client (>= 6.8.1)
- Serilog.AspNetCore (>= 10.0.0)
- Serilog.Exceptions (>= 8.4.0)
- Serilog.Sinks.Console (>= 6.1.1)
- Serilog.Sinks.Debug (>= 3.0.0)
- Serilog.Sinks.OpenTelemetry (>= 4.2.0)
- StackExchange.Redis (>= 2.13.17)
- Swashbuckle.AspNetCore (>= 10.2.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.98 | 35 | 9/19/2026 |
| 1.0.97 | 35 | 9/19/2026 |
| 1.0.96 | 54 | 9/16/2026 |
| 1.0.95 | 69 | 9/11/2026 |
| 1.0.94 | 54 | 9/11/2026 |
| 1.0.93 | 58 | 9/11/2026 |
| 1.0.92 | 74 | 9/5/2026 |
| 1.0.91 | 62 | 8/31/2026 |
| 1.0.90 | 65 | 8/30/2026 |
| 1.0.89 | 89 | 8/29/2026 |
| 1.0.88 | 91 | 8/19/2026 |
| 1.0.87 | 74 | 8/18/2026 |
| 1.0.86 | 77 | 8/17/2026 |
| 1.0.85 | 85 | 8/11/2026 |
| 1.0.84 | 65 | 8/9/2026 |
| 1.0.83 | 113 | 8/8/2026 |
| 1.0.82 | 141 | 7/23/2026 |
| 1.0.81 | 111 | 7/23/2026 |
| 1.0.80 | 115 | 7/23/2026 |
| 1.0.79 | 113 | 7/23/2026 |