PolyhydraGames.Core.AspNet
2.0.0.17
dotnet add package PolyhydraGames.Core.AspNet --version 2.0.0.17
NuGet\Install-Package PolyhydraGames.Core.AspNet -Version 2.0.0.17
<PackageReference Include="PolyhydraGames.Core.AspNet" Version="2.0.0.17" />
<PackageVersion Include="PolyhydraGames.Core.AspNet" Version="2.0.0.17" />
<PackageReference Include="PolyhydraGames.Core.AspNet" />
paket add PolyhydraGames.Core.AspNet --version 2.0.0.17
#r "nuget: PolyhydraGames.Core.AspNet, 2.0.0.17"
#:package PolyhydraGames.Core.AspNet@2.0.0.17
#addin nuget:?package=PolyhydraGames.Core.AspNet&version=2.0.0.17
#tool nuget:?package=PolyhydraGames.Core.AspNet&version=2.0.0.17
Core.AspNet
Shared ASP.NET Core helpers used across PolyhydraGames services and clients. The package focuses on common identity, logging, and controller building blocks so you can keep app code small and consistent.
Tags
- dotnet
- core
- core-asp-net
- docs
- testing
- devops
Related Repos
Features
- Base API controllers for DTO and named DTO read endpoints
- Identity services for API, Blazor Server, and client-side apps
- OpenId Connect refresh token support
- Owner ID middleware for propagating authenticated user ID
- Jwt and HttpContext helpers
- Logging registration with Seq support
Requirements
- .NET SDK 10.0 (targets
net10.0) - ASP.NET Core authentication packages (transitive via NuGet)
Installation
dotnet add package PolyhydraGames.Core.AspNet
Quick Start
Register logging
var builder = WebApplication.CreateBuilder(args);
builder.AddLogs();
Add owner middleware
var app = builder.Build();
app.UseAuthentication();
app.UseOwnerMiddleware();
Add refresh middleware
var app = builder.Build();
app.UseAuthentication();
app.UseRefreshMiddleware();
Use base controllers
public class WidgetsController : DtoBaseController<WidgetDto>
{
public WidgetsController(IReadByIdServiceAsync<WidgetDto> repo) : base(repo) { }
}
Configure identity services
// API
services.AddScoped<IIdentityService, ApiIdentityService>();
// Blazor Server
services.AddScoped<IIdentityService, ServerSideIdentityService>();
// Client-side (OidcClient provided by your app)
services.AddScoped<IAuthenticationClient, ClientSideIdentityService>();
Configuration
Refresh middleware
Refresh middleware expects standard OIDC configuration keys:
OIDC:Authority
OIDC:ClientId
OIDC:ClientSecret
The middleware uses OIDC discovery to resolve the token endpoint and stores refreshed
tokens in authentication properties so GetTokenAsync continues to work.
Token expiration
Token expiry checks use the standard JWT exp claim via JwtSecurityToken.ValidTo.
If the access token is missing or empty, it is treated as expired.
API Notes
Controllers
DtoBaseController<T>exposesItems,Page,Count,Any, andItemById.NamedDtoBaseController<T>adds name-based queries likeItemsByNameandItemByName.- Use
IReadByIdServiceAsync<T>for DTO controllers andINamedReadServiceAsync<T>for named DTO controllers to enforce compile-time contracts.
Identity services
ApiIdentityServiceis for API hosts where owner ID is provided in tokens.ServerSideIdentityServicelistens toAuthenticationStateProviderin Blazor Server.ClientSideIdentityServicewrapsOidcClientfor interactive login flows.AuthenticationStateExtensions.ToPrincipalContext()andAuthenticationStateProvider.GetCurrentPrincipalContextAsync()provide a reusable authenticated-principal snapshot containing the source principal, authentication status, owner ID, and best-effort display username. Use these helpers when app-level authorization needs principal claims before local app-user records have hydrated.
Middleware
OwnerMiddlewaresetsIIdentityService.OwnerIdandAuthorizationToken.RefreshMiddlewareattempts a refresh token flow when JWTs are expired.
Build and Test
dotnet build
dotnet test
Sample Host (Middleware Testing)
A minimal sample app is available at samples/CoreAspNet.SampleHost/ to exercise UseOwnerMiddleware() and UseRefreshMiddleware().
Quick test flow
# from repo root
cd /home/lancer1977/code/Core.AspNet
# run the sample host
dotnet run --project samples/CoreAspNet.SampleHost
In another terminal:
curl http://localhost:5000/debug/identity
Expected result: JSON containing OwnerId, HasAccessToken, and token metadata populated by the sample auth handler + middleware.
appsettings.Development.json in the sample includes placeholder OIDC:* keys:
OIDC:AuthorityOIDC:ClientIdOIDC:ClientSecret
Contributing
- Keep public APIs documented with XML comments.
- Add tests for new middleware or identity behaviors.
- Follow existing naming and namespace conventions.
CI/CD Configuration
GitHub Actions handles build, test, pack, and publish.
Workflows
ci.ymlbuilds and tests on pushes and pull requests.publish.ymlvalidates, packs, and publishes to NuGet.org only for version tags (v<PackageVersion>) or an explicit manual dispatch. It never publishes on a branch push.
Package Publishing
NuGet.org is the canonical package host. The currently published source version is
1.1.0.1; update <Version> in src/PolyhydraGames.Core.AspNet.csproj before
creating a future v<PackageVersion> release tag. The package workflow verifies
the package identity, version, and README inclusion before release.
📖 Documentation
Detailed documentation can be found in the following sections:
| 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
- IdentityModel.OidcClient (>= 6.0.0)
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 10.0.9)
- Microsoft.Extensions.Configuration (>= 10.0.9)
- PolyhydraGames.Core.Interfaces (>= 3.0.0.14)
- PolyhydraGames.Extensions (>= 2.1.1.78)
- PolyhydraGames.Identity.Contracts (>= 0.1.0)
- Seq.Extensions.Logging (>= 9.0.0)
- System.Reactive (>= 6.1.0)
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 |
|---|---|---|
| 2.0.0.17 | 65 | 10/14/2026 |
| 1.1.0.1 | 5,205 | 7/9/2026 |
| 1.0.2.48 | 2,927 | 6/7/2026 |
| 1.0.2.47 | 128 | 6/7/2026 |
| 1.0.2.46 | 136 | 6/7/2026 |
| 1.0.2.45 | 209 | 5/29/2026 |
| 1.0.2.44 | 156 | 5/23/2026 |
| 1.0.2.43 | 526 | 4/7/2026 |
| 1.0.2.42 | 186 | 4/4/2026 |
| 1.0.2.41 | 199 | 3/30/2026 |
| 1.0.2.38 | 202 | 3/23/2026 |
| 1.0.2.36 | 280 | 2/14/2026 |
| 1.0.2.34 | 193 | 1/29/2026 |
| 1.0.2.32 | 214 | 1/26/2026 |
| 1.0.2.31 | 157 | 1/26/2026 |
| 1.0.2.30 | 162 | 1/26/2026 |
| 1.0.2.28 | 553 | 12/11/2025 |
| 1.0.2.27 | 276 | 12/5/2025 |
| 1.0.2.26 | 438 | 11/30/2025 |
| 1.0.2.25 | 350 | 11/16/2025 |