Rampart.AspNetCore 0.1.0

dotnet add package Rampart.AspNetCore --version 0.1.0
                    
NuGet\Install-Package Rampart.AspNetCore -Version 0.1.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="Rampart.AspNetCore" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rampart.AspNetCore" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Rampart.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 Rampart.AspNetCore --version 0.1.0
                    
#r "nuget: Rampart.AspNetCore, 0.1.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 Rampart.AspNetCore@0.1.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=Rampart.AspNetCore&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Rampart.AspNetCore&version=0.1.0
                    
Install as a Cake Tool

Rampart.AspNetCore

ASP.NET Core middleware for verifying Rampart JWTs. Handles JWKS fetching, RS256 verification, claim extraction, and role-based authorization with zero configuration beyond the issuer URL.

Install

dotnet add package Rampart.AspNetCore

Requires .NET 8.0 or later.

Quick Start

Configure authentication in Program.cs:

using Rampart.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRampartAuth("http://localhost:8080");
builder.Services.AddControllers();

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();

app.Run();

Protect a controller:

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Rampart.AspNetCore;

[ApiController]
[Route("api")]
[Authorize]
public class ProfileController : ControllerBase
{
    [HttpGet("me")]
    public IActionResult Me()
    {
        var claims = RampartClaims.FromPrincipal(User);
        return Ok(new { userId = claims.Sub, org = claims.OrgId });
    }
}

Configuration

AddRampartAuth(issuer)

Call on IServiceCollection to configure JWT Bearer authentication:

builder.Services.AddRampartAuth("https://auth.example.com");

This:

  1. Fetches the JWKS from {issuer}/.well-known/jwks.json (cached automatically)
  2. Validates RS256 signatures, issuer, and token expiry
  3. Maps the roles JWT claim to ClaimsPrincipal role claims for [Authorize(Roles = "...")]

Claims

RampartClaims

Typed representation of Rampart JWT claims. Extract from the authenticated user:

var claims = RampartClaims.FromPrincipal(User);
Property Type Description
Sub string User ID (UUID)
OrgId string? Organization ID (UUID)
PreferredUsername string? Username
Email string? Email address
EmailVerified bool Whether email is verified
GivenName string? First name (if set)
FamilyName string? Last name (if set)
Roles IReadOnlyList<string> Assigned roles

Claims middleware

Optionally, register the claims middleware to make RampartClaims available via HttpContext.Items:

app.UseAuthentication();
app.UseRampartClaims(); // extracts claims into HttpContext.Items
app.UseAuthorization();

Then access claims from anywhere with access to HttpContext:

var claims = HttpContext.GetRampartClaims();

Role-Based Authorization

Rampart roles are mapped to ASP.NET Core role claims automatically:

[Authorize(Roles = "admin")]
[HttpGet("admin/dashboard")]
public IActionResult Dashboard() => Ok(new { area = "admin" });

[Authorize(Roles = "editor,admin")]
[HttpPost("articles")]
public IActionResult CreateArticle() => Ok();

Using [RequireRoles] attribute

For Rampart-specific error format (matches other adapter error responses):

[Authorize]
[RequireRoles("editor")]
[HttpPut("articles/{id}")]
public IActionResult UpdateArticle(string id) => Ok();

Using middleware

For route-group-level role enforcement:

app.UseAuthentication();
app.UseAuthorization();

app.Map("/api/admin", adminApp =>
{
    adminApp.RequireRampartRoles("admin");
    // ... admin routes
});

Error Responses

On authentication failure, returns a 401 JSON response matching Rampart's error format:

{
  "error": "unauthorized",
  "error_description": "Missing or invalid authorization header.",
  "status": 401
}

On authorization failure (missing roles), returns 403:

{
  "error": "forbidden",
  "error_description": "Missing required role(s): admin, editor",
  "status": 403
}

API Reference

Method / Class Description
AddRampartAuth(issuer) Configures JWT Bearer auth with Rampart JWKS
RampartClaims.FromPrincipal(user) Extracts typed claims from ClaimsPrincipal
UseRampartClaims() Middleware to set HttpContext.Items["RampartClaims"]
HttpContext.GetRampartClaims() Gets typed claims from HttpContext.Items
[RequireRoles("role")] Authorization filter with Rampart error format
RequireRampartRoles("role") Inline middleware for role enforcement

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.1.0 90 3/15/2026