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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Modgud.Client.AspNetCore" Version="0.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Modgud.Client.AspNetCore" Version="0.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Modgud.Client.AspNetCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Modgud.Client.AspNetCore --version 0.5.0
                    
#r "nuget: Modgud.Client.AspNetCore, 0.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Modgud.Client.AspNetCore@0.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Modgud.Client.AspNetCore&version=0.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Modgud.Client.AspNetCore&version=0.5.0
                    
Install as a Cake Tool

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:

  1. Fetches {Authority}/connect/userinfo on token validation and merges the resource_access[<audience>] block onto the principal.
  2. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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