Modgud.Client.AspNetCore
0.5.0
dotnet add package Modgud.Client.AspNetCore --version 0.5.0
NuGet\Install-Package Modgud.Client.AspNetCore -Version 0.5.0
<PackageReference Include="Modgud.Client.AspNetCore" Version="0.5.0" />
<PackageVersion Include="Modgud.Client.AspNetCore" Version="0.5.0" />
<PackageReference Include="Modgud.Client.AspNetCore" />
paket add Modgud.Client.AspNetCore --version 0.5.0
#r "nuget: Modgud.Client.AspNetCore, 0.5.0"
#:package Modgud.Client.AspNetCore@0.5.0
#addin nuget:?package=Modgud.Client.AspNetCore&version=0.5.0
#tool nuget:?package=Modgud.Client.AspNetCore&version=0.5.0
Modgud.Client.AspNetCore
ASP.NET Core integration for resource servers that authenticate against a Modgud identity provider.
The lib does two things on top of vanilla AddJwtBearer:
- Fetches
{Authority}/connect/userinfoon token validation and merges theresource_access[<audience>]block onto the principal. - Flattens that block into native
ClaimTypes.Role/"permission"/"group"claims so[Authorize(Roles = "...")]and an.RequiresCocoarPermission("...")endpoint filter work natively.
Bypass tiers (realm:admin, <resource>:admin) are pre-expanded
IdP-side before emission, so the client lib does pure
exact-match — no evaluator logic, no HTTP client, no caching.
Install
dotnet add package Modgud.Client.AspNetCore
Quickstart
using Modgud.Client.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = "https://auth.example.com";
options.Audience = "event-tree-api"; // matches an OAuthApi in the IdP
});
builder.Services.AddModgudClient(o =>
{
o.Authority = "https://auth.example.com";
o.Audience = "event-tree-api"; // same value as above
});
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
// Role-gated — uses the standard [Authorize] attribute since
// roles are projected to ClaimTypes.Role.
app.MapGet("/admin/ping", () => "pong")
.RequireAuthorization(p => p.RequireRole("Editor"));
// Permission-gated — bare 2-segment string. The IdP has already
// expanded realm:admin / <resource>:admin to catalog entries, so
// this is a pure contains-check.
app.MapPost("/calendars/{id}", (string id) => Results.Ok())
.RequiresCocoarPermission("calendar:write");
app.Run();
How the claims land on the principal
The IdP emits permissions per audience in Keycloak shape:
"resource_access": {
"event-tree-api": {
"roles": ["Editor", "Viewer"],
"permissions": ["calendar:read", "calendar:write"],
"group": ["Calendar Team"]
}
}
ModgudClaimsTransformation projects that into flat claims:
| Source field | Flat claim type |
|---|---|
roles |
ClaimTypes.Role |
permissions |
"permission" |
group |
"group" |
Read them with standard claims APIs:
var perms = ctx.User.FindAll("permission").Select(c => c.Value);
Configuration reference
| Option | Description |
|---|---|
Authority |
IdP base URL. Used to fetch {Authority}/connect/userinfo. Same value as JwtBearerOptions.Authority. |
Audience |
The audience this resource server identifies as — same value as JwtBearerOptions.Audience. Looked up against resource_access[…]. |
JwtBearerScheme |
Scheme name to attach to. Defaults to "Bearer". |
License
Apache-2.0. See LICENSE.
| 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.8)
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 |
|---|---|---|
| 0.5.0 | 100 | 5/27/2026 |