Sprint.Shared.Authentication
1.0.0
dotnet add package Sprint.Shared.Authentication --version 1.0.0
NuGet\Install-Package Sprint.Shared.Authentication -Version 1.0.0
<PackageReference Include="Sprint.Shared.Authentication" Version="1.0.0" />
<PackageVersion Include="Sprint.Shared.Authentication" Version="1.0.0" />
<PackageReference Include="Sprint.Shared.Authentication" />
paket add Sprint.Shared.Authentication --version 1.0.0
#r "nuget: Sprint.Shared.Authentication, 1.0.0"
#:package Sprint.Shared.Authentication@1.0.0
#addin nuget:?package=Sprint.Shared.Authentication&version=1.0.0
#tool nuget:?package=Sprint.Shared.Authentication&version=1.0.0
Shared.Authentication
JWT Bearer authentication library designed for the Sprint ecosystem (.NET 10+). Handles JWT validation, distributed cache session lookup, role-based access control, and populates a scoped CurrentUser context object — all wired up with a single AddSharedAuthentication call.
Key Features
- JWT Validation: Validates tokens using RSA Public Key via
Microsoft.AspNetCore.Authentication.JwtBearer. - Session Cache (Optional): Caches resolved
Actordata inIDistributedCache(Redis, Memory, etc.) to reduce Auth Service round-trips. Gracefully degrades if no cache is registered. - Role-Based Access Control: Validates that the actor holds a permitted role via
IClaimManagementServicebefore the request proceeds. - Scoped
CurrentUser: Populates a DI-injectableCurrentUserobject with identity and claim data (company, role, application, vendor) on every validated request. - Token Expiry Header: Automatically sets
Token-Expired: trueresponse header when a token has expired. - Requires .NET 10.0+
Installation & Setup
1. Register Services in Program.cs
using Shared.Authentication.Extensions;
// Option 1: Automatic from Configuration
builder.Services.AddSharedAuthentication(builder.Configuration);
// Option 2: Manual setup via Action
builder.Services.AddSharedAuthentication(options => {
options.JwtSettings = new Jwt {
PublicKey = "-----BEGIN PUBLIC KEY-----...",
GetSessionBySessionIdUrl = "https://auth-service/api/session/"
};
options.IsCacheEnabled = true;
options.CacheDurationInSec = 900; // 15 minutes
});
2. Enable Middleware in Program.cs
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.Run();
3. Configuration Template (appsettings.json)
{
"Jwt": {
"PublicKey": "-----BEGIN PUBLIC KEY-----\nMIIB...\n-----END PUBLIC KEY-----",
"GetSessionBySessionIdUrl": "https://auth-service.internal/api/session/"
},
"CacheSetting": {
"Token": {
"Enabled": true,
"DurationInSec": 900
}
}
}
Using CurrentUser in Controllers / Services
Inject CurrentUser directly — it is populated automatically after JWT validation:
public class OrderEndpoint : Endpoint<OrderRequest>
{
private readonly CurrentUser _currentUser;
public OrderEndpoint(CurrentUser currentUser)
{
_currentUser = currentUser;
}
public override async Task HandleAsync(OrderRequest req, CancellationToken ct)
{
var userId = _currentUser.Id;
var userName = _currentUser.Name;
var roles = _currentUser.ClaimRoleIds; // comma-separated role IDs
var companies = _currentUser.ClaimCompanyCodes; // comma-separated company codes
await SendOkAsync(ct);
}
}
CurrentUser Properties
| Property | Type | Description |
|---|---|---|
| Id | string? |
Actor ID from session |
| Name | string? |
Actor display name |
| SessionId | string? |
Session identifier from JWT claim |
| ClaimCompanyIds | string? |
Comma-separated company IDs |
| ClaimCompanyCodes | string? |
Comma-separated company codes |
| ClaimCompanyNames | string? |
Comma-separated company names |
| ClaimRoleIds | string? |
Comma-separated role IDs |
| ClaimRoleCodes | string? |
Comma-separated role codes |
| ClaimRoleNames | string? |
Comma-separated role names |
| ClaimApplicationIds | string? |
Comma-separated application IDs |
| ClaimApplicationCodes | string? |
Comma-separated application codes |
| ClaimApplicationNames | string? |
Comma-separated application names |
| ClaimVendorCode | string? |
Vendor code (nullable) |
| ClaimCompanyBranch | string? |
Company branch (nullable) |
Helper: IsValidUserId
Checks if the given userId matches the current actor, or if the actor has admin role (Role ID 4):
if (!_currentUser.IsValidUserId(req.TargetUserId))
{
await SendForbiddenAsync(ct);
return;
}
Optional: Distributed Cache (Redis)
When IsCacheEnabled = true, the library will use IDistributedCache if one is registered. If none is registered, it falls back to calling the Auth Service on every request without crashing.
// Register Redis cache before AddSharedAuthentication
builder.Services.AddStackExchangeRedisCache(options => {
options.Configuration = builder.Configuration.GetConnectionString("Redis");
});
builder.Services.AddSharedAuthentication(builder.Configuration);
Dependencies
| Package | Version |
|---|---|
Microsoft.AspNetCore.Authentication.JwtBearer |
10.0.1 |
Utility.Package |
10.0.2 |
© 2026 Sprint-OMS Development Team
| 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.AspNetCore.Authentication.JwtBearer (>= 10.0.1)
- Utility.Package (>= 10.0.2)
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.0 | 164 | 4/20/2026 |