Modgud.AspNetCore.ResourceServer
0.9.0
See the version list below for details.
dotnet add package Modgud.AspNetCore.ResourceServer --version 0.9.0
NuGet\Install-Package Modgud.AspNetCore.ResourceServer -Version 0.9.0
<PackageReference Include="Modgud.AspNetCore.ResourceServer" Version="0.9.0" />
<PackageVersion Include="Modgud.AspNetCore.ResourceServer" Version="0.9.0" />
<PackageReference Include="Modgud.AspNetCore.ResourceServer" />
paket add Modgud.AspNetCore.ResourceServer --version 0.9.0
#r "nuget: Modgud.AspNetCore.ResourceServer, 0.9.0"
#:package Modgud.AspNetCore.ResourceServer@0.9.0
#addin nuget:?package=Modgud.AspNetCore.ResourceServer&version=0.9.0
#tool nuget:?package=Modgud.AspNetCore.ResourceServer&version=0.9.0
Modgud.AspNetCore.ResourceServer
ASP.NET Core integration for APIs protected by a Modgud identity provider.
The package has one registration method and one public authentication scheme.
ModgudTokenMode controls whether the API accepts self-contained JWTs, opaque
reference tokens, or both. In Both mode, the package routes three-part JWTs to
local validation and opaque tokens to RFC 7662 introspection.
Both validation paths select resource_access[<audience>] and project its roles
and permissions onto the authenticated identity. Roles use ClaimTypes.Role;
permissions use ModgudClaimTypes.Permission.
Install
dotnet add package Modgud.AspNetCore.ResourceServer
JWT quickstart
JWT is the default mode:
using Modgud.AspNetCore.ResourceServer;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddModgudResourceServer(options =>
{
options.Authority = "https://auth.example.com";
options.Audience = "event-tree-api";
});
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapGet("/admin/ping", () => "pong")
.RequireAuthorization(policy => policy.RequireRole("Editor"));
app.MapPost("/calendars/{id}", (string id) => Results.Ok())
.RequireModgudPermission("calendar:write");
app.Run();
JWT mode makes no per-request call to Modgud. A token must contain the
configured audience and its resource_access block. There is deliberately no
UserInfo fallback.
Reference-token mode
builder.Services.AddModgudResourceServer(options =>
{
options.Authority = "https://auth.example.com";
options.Audience = "event-tree-api";
options.TokenMode = ModgudTokenMode.OnlyReferenceToken;
options.IntrospectionClientSecret =
builder.Configuration["Modgud:IntrospectionSecret"];
});
The resource server authenticates to /connect/introspect with a confidential
OAuth client. IntrospectionClientId defaults to Audience; in the usual setup
the introspection client's ID therefore equals the resource-server audience.
Validation is fail-closed and uncached, so revocation takes effect on the next
request.
Accept both formats
builder.Services.AddModgudResourceServer(options =>
{
options.Authority = "https://auth.example.com";
options.Audience = "event-tree-api";
options.TokenMode = ModgudTokenMode.Both;
options.IntrospectionClientSecret =
builder.Configuration["Modgud:IntrospectionSecret"];
});
The application still exposes one authentication scheme. Token shape only
selects the internal validator; it never bypasses signature, issuer, audience,
expiry, active-state, or DPoP validation. A second
AddModgudResourceServer(...) call is rejected.
Permission gates
RequireModgudPermission adds normal ASP.NET Core authorization metadata. It
works on both RouteHandlerBuilder and RouteGroupBuilder and yields 401 for
anonymous callers or 403 for authenticated callers without the exact
permission:
var writeApi = app.MapGroup("/write")
.RequireModgudPermission("calendar:write");
Bypass grants such as realm:admin and <resource>:admin are expanded by the
IdP before token issuance. The resource server performs only an exact claim
check.
Claims
Given:
"resource_access": {
"event-tree-api": {
"roles": ["Editor"],
"permissions": ["calendar:read", "calendar:write"]
}
}
read the projected values with:
var roles = user.FindAll(ClaimTypes.Role).Select(claim => claim.Value);
var permissions = user.FindAll(ModgudClaimTypes.Permission)
.Select(claim => claim.Value);
Configuration
| Option | Description |
|---|---|
Authority |
Required realm host root. |
Audience |
Required token audience and resource_access key. |
TokenMode |
OnlyJwt (default), OnlyReferenceToken, or Both. |
IntrospectionClientId |
Introspection client ID; defaults to Audience. |
IntrospectionClientSecret |
Required when the mode accepts reference tokens. |
RequireHttpsMetadata |
Requires an HTTPS authority; defaults to true. |
ConfigureJwtBearer |
Optional advanced JWT bearer configuration in JWT-capable modes. |
The valid option combination is checked immediately during registration.
required properties cannot express the mode-dependent secret requirement, so
invalid combinations fail with OptionsValidationException.
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.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.