Zymergi.Identity.Auth0
11.4.0-alpha
dotnet add package Zymergi.Identity.Auth0 --version 11.4.0-alpha
NuGet\Install-Package Zymergi.Identity.Auth0 -Version 11.4.0-alpha
<PackageReference Include="Zymergi.Identity.Auth0" Version="11.4.0-alpha" />
<PackageVersion Include="Zymergi.Identity.Auth0" Version="11.4.0-alpha" />
<PackageReference Include="Zymergi.Identity.Auth0" />
paket add Zymergi.Identity.Auth0 --version 11.4.0-alpha
#r "nuget: Zymergi.Identity.Auth0, 11.4.0-alpha"
#:package Zymergi.Identity.Auth0@11.4.0-alpha
#addin nuget:?package=Zymergi.Identity.Auth0&version=11.4.0-alpha&prerelease
#tool nuget:?package=Zymergi.Identity.Auth0&version=11.4.0-alpha&prerelease
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 = ...; }), thenRequireAuthorization). UseAuth0TokenValidatoronly where you must validate a token in code. - Register
Auth0ManagementClientas a singleton with its ownHttpClient. It caches the management token, refreshes it 60 s before expiry under a lock, and sets theAuthorizationheader on that client. Do not share thatHttpClientwith other code, and do not use a typedIHttpClientFactoryclient (a new instance per request would fetch a new token every time). - Register
Auth0TokenValidatoras 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
CancellationTokento 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
IAuthManagementClientand use a fake in unit tests. - To test the real client, give it an
HttpClientover a stubHttpMessageHandler, 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
emailornametoClaimTypes.EmailorClaimTypes.Name. Read the shortemailandnameclaims. Because the name claim type isClaimTypes.Name,principal.Identity.Nameis null. - Role claims named
role,roles, or ending in/rolesare copied toClaimTypes.Role, soIsInRoleworks. ClaimsListinZymergi.AspNetCoreis 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
HttpClientyou pass in, so a stub handler can intercept them. - Auth0.ManagementApi 10.5.0.
| 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
- Auth0.ManagementApi (>= 10.5.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.12)
- Microsoft.Extensions.Hosting (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.12)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.23.0)
- Newtonsoft.Json (>= 13.0.4)
- System.IdentityModel.Tokens.Jwt (>= 8.23.0)
- Zymergi.Core (>= 11.4.0-alpha)
- Zymergi.Social (>= 11.4.0-alpha)
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 |