AuthAction.AspNetCore
0.1.1
dotnet add package AuthAction.AspNetCore --version 0.1.1
NuGet\Install-Package AuthAction.AspNetCore -Version 0.1.1
<PackageReference Include="AuthAction.AspNetCore" Version="0.1.1" />
<PackageVersion Include="AuthAction.AspNetCore" Version="0.1.1" />
<PackageReference Include="AuthAction.AspNetCore" />
paket add AuthAction.AspNetCore --version 0.1.1
#r "nuget: AuthAction.AspNetCore, 0.1.1"
#:package AuthAction.AspNetCore@0.1.1
#addin nuget:?package=AuthAction.AspNetCore&version=0.1.1
#tool nuget:?package=AuthAction.AspNetCore&version=0.1.1
AuthAction.AspNetCore
ASP.NET Core JWT authentication middleware for AuthAction. One call to AddAuthAction() configures JWT Bearer authentication, JWKS key fetching and caching, audience validation, and the [CurrentUser] parameter attribute.
Prerequisites
- .NET 8+
- An AuthAction tenant with an API registered
Installation
dotnet add package AuthAction.AspNetCore
Quick start
1. Add credentials to appsettings.json:
{
"AuthAction": {
"Domain": "myapp.eu.authaction.com",
"Audience": "https://api.myapp.com"
}
}
2. Register the middleware in Program.cs:
using AuthAction.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthAction(options =>
builder.Configuration.GetSection("AuthAction").Bind(options));
builder.Services.AddAuthorization();
builder.Services.AddControllers();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
3. Protect routes and inject the current user:
using AuthAction.AspNetCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("[controller]")]
public class ProfileController : ControllerBase
{
[HttpGet]
[Authorize]
public IActionResult Get([CurrentUser] UserInfo user) =>
Ok(new { user.Sub, user.Email });
}
Configuration
| Key | Required | Description |
|---|---|---|
AuthAction:Domain |
Yes | AuthAction tenant domain, e.g. myapp.eu.authaction.com |
AuthAction:Audience |
Yes | API identifier registered in AuthAction (the JWT aud claim) |
You can also configure via environment variables using ASP.NET Core's double-underscore convention:
export AUTHACTION__DOMAIN=myapp.eu.authaction.com
export AUTHACTION__AUDIENCE=https://api.myapp.com
[CurrentUser] attribute
Add [CurrentUser] UserInfo user to any [Authorize]-protected action parameter to receive a typed object populated from the verified JWT claims.
[HttpGet("/me")]
[Authorize]
public IActionResult Me([CurrentUser] UserInfo user) =>
Ok(new
{
user.Sub,
user.Email,
user.EmailVerified,
user.Name,
user.Picture,
});
UserInfo exposes the standard OIDC claims plus a Claims dictionary for any custom claims:
| Property | JWT claim | Type |
|---|---|---|
Sub |
sub |
string |
Email |
email |
string? |
EmailVerified |
email_verified |
bool |
Name |
name |
string? |
Picture |
picture |
string? |
Claims |
all claims | IReadOnlyDictionary<string, string> |
How it works
AddAuthAction() calls AddJwtBearer() with Authority set to https://<domain>. ASP.NET Core's built-in JWT Bearer middleware:
- Fetches
https://<domain>/.well-known/openid-configurationto discover the JWKS URI. - Downloads and caches the public keys from the JWKS endpoint.
- Validates RS256 signature, issuer, audience, and token expiry on every request.
- Re-fetches keys automatically when an unknown
kidis encountered (key rotation).
No manual JWKS handling or caching is required.
Running the tests
dotnet test
The test suite uses WebApplicationFactory with a fake authentication handler — no real JWKS calls are made.
Example app
See authaction-dotnet-example for a full ASP.NET Core Web API example.
License
MIT
| Product | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.27)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.