Zymergi.Identity.Auth0 11.4.0-alpha

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

Zymergi.Identity.Auth0

Auth0 Management API v2 client (Auth0ManagementClient, implementing IAuthManagementClient from Zymergi.Core) for creating and removing users and assigning roles, plus Auth0TokenValidator for validating an Auth0 JWT in code. It does not do login or logout.

Targets .NET 10. Depends on Zymergi.Core and Zymergi.Social.

Install

dotnet add package Zymergi.Identity.Auth0

Register in Program.cs

{
  "Auth0": {
    "Domain": "your-tenant.auth0.com",
    "ClientId": "management-api-client-id",
    "Authority": "https://your-tenant.auth0.com",
    "DatabaseConnection": "Username-Password-Authentication"
  }
}

Keep the secret out of the file: dotnet user-secrets set "Auth0:Secret" "...", or the environment variable Auth0__Secret, or a vault provider.

Audience is optional and defaults to Domain. Authority is optional; when it is empty the issuer is https://{Domain}/. DatabaseConnection is optional; user create then uses Username-Password-Authentication.

using Microsoft.Extensions.Options;
using Zymergi.Identity;
using Zymergi.Identity.Auth0;

builder.Services.AddAuth0Settings(builder.Configuration);   // binds "Auth0", validates on start

builder.Services.AddSingleton<IAuthManagementClient>(sp =>
    new Auth0ManagementClient(
        sp.GetRequiredService<IOptions<Auth0Settings>>().Value,
        new HttpClient(new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(5) })));

builder.Services.AddSingleton(sp =>
    new Auth0TokenValidator(sp.GetRequiredService<IOptions<Auth0Settings>>().Value));

AddAuth0Settings fails at startup when Domain, ClientId, or Secret is missing, or when Authority is not an absolute http or https URI.

Use it

app.MapPost("/admin/users", async (NewUser body, IAuthManagementClient auth, CancellationToken ct) =>
{
    if ((await auth.GetUsersByEmailAsync(body.Email, ct)).Any())
        return Results.Problem(statusCode: 409, title: "User exists");
    var user = await auth.AddUserAsync(body.Email, body.TemporaryPassword, forceVerifyEmail: true, ct);
    await auth.AddRoleToAllUsersWithEmailAsync(body.Email, "member", ct);
    return Results.Created($"/admin/users/{user.Id}", user);
}).RequireAuthorization("admin");

public sealed record NewUser(string Email, string TemporaryPassword);

Validating a token you received yourself (for example an ID token posted by a client):

ClaimsPrincipal principal = await validator.ValidateAsync(idToken, ct);
string? email = principal.FindFirst("email")?.Value;
bool isAdmin = principal.IsInRole("admin");

Best practices

  • Protect API endpoints with the standard JWT bearer handler (Microsoft.AspNetCore.Authentication.JwtBearer: AddAuthentication().AddJwtBearer(o => { o.Authority = ...; o.Audience = ...; }), then RequireAuthorization). Use Auth0TokenValidator only where you must validate a token in code.
  • Register Auth0ManagementClient as a singleton with its own HttpClient. It caches the management token, refreshes it 60 s before expiry under a lock, and sets the Authorization header on that client. Do not share that HttpClient with other code, and do not use a typed IHttpClientFactory client (a new instance per request would fetch a new token every time).
  • Register Auth0TokenValidator as a singleton. It caches the tenant's signing keys; a new instance per request fetches the OpenID configuration again.
  • Bind settings with IOptions<Auth0Settings> (AddAuth0Settings), so bad configuration fails at startup.
  • Pass the request's CancellationToken to every call.
  • Never log tokens or the client secret.
  • Lookups by email retry only after HTTP 429. Keep management calls out of hot request paths; cache roles if you read them often.

Testing

  • Depend on IAuthManagementClient and use a fake in unit tests.
  • To test the real client, give it an HttpClient over a stub HttpMessageHandler, as this repository's unit tests do. No test should call a real Auth0 tenant.
  • Build Auth0TokenValidator(TokenValidationParameters) with a test signing key to validate tokens you mint in the test.

Gotchas

  • On this version the validator does not map email or name to ClaimTypes.Email or ClaimTypes.Name. Read the short email and name claims. Because the name claim type is ClaimTypes.Name, principal.Identity.Name is null.
  • Role claims named role, roles, or ending in /roles are copied to ClaimTypes.Role, so IsInRole works.
  • ClaimsList in Zymergi.AspNetCore is obsolete. It reads a JWT without validating it.
  • The constructor makes no network call. The first management call fetches the token.

Version notes

11.4.0-alpha: no API change.

11.3.0-alpha

  • The first management call loads a token. Before, it threw ArgumentOutOfRangeException.
  • Management API calls use the HttpClient you pass in, so a stub handler can intercept them.
  • Auth0.ManagementApi 10.5.0.

Source: bitbucket.org/zymergy/zymergi.saas

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
11.4.0-alpha 70 11/16/2026
11.3.0-alpha 75 11/12/2026
11.2.0-alpha 66 11/2/2026
11.1.1-alpha 95 10/4/2026
11.1.0-alpha 111 10/1/2026
11.0.6-alpha 97 7/10/2026
11.0.5-alpha 135 7/9/2026
11.0.4-alpha 81 7/6/2026
11.0.3-alpha 85 7/6/2026
11.0.2-alpha 123 6/30/2026
11.0.1-alpha 121 6/30/2026
11.0.0-alpha 102 6/29/2026