Home / Developers / Quickstarts / .NET
Quickstart: .NET
Verify the sign-in token, handle back-channel logout, and verify then handle lifecycle webhooks with AuthVertex.Sdk, AuthVertex.Sdk.AspNetCore and AuthVertex.Events. .NET 8 or newer.
Install
Coming — available at release. When the packages are released, you will install them with:
dotnet add package AuthVertex.Sdk --prerelease
dotnet add package AuthVertex.Sdk.AspNetCore --prerelease
dotnet add package AuthVertex.Events --prereleaseAuthVertex.Sdk verifies ID and access tokens, back-channel logout tokens and webhook signatures, with no runtime dependencies. AuthVertex.Sdk.AspNetCore adds an ASP.NET Core authentication handler and endpoints for the logout and webhook receivers; every check is still done by AuthVertex.Sdk. AuthVertex.Events turns a verified webhook body into a typed record. All three target .NET 8 or newer.
Sign-in itself is standard OpenID Connect: any OIDC client library performs the authorization code flow with PKCE. The SDK checks the tokens you get back.
Configure
using AuthVertex.Sdk;
using AuthVertex.Sdk.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
var issuer = app.Configuration["AuthVertex:Issuer"]!;
var clientId = app.Configuration["AuthVertex:ClientId"]!;
// The issuer's signing keys, found through OIDC discovery. Cached, refreshed on a new key, fails closed.
var keys = new RemoteJwks(await OidcDiscovery.DiscoverJwksUriAsync(issuer));
var tokens = new TokenVerifier { Issuer = issuer, Audience = clientId, Keys = keys };Verify the sign-in token
After your OIDC client library has exchanged the authorization code at the token endpoint, verify the ID token with the nonce you sent:
Claims id = await tokens.VerifyIdTokenAsync(idToken, new IdTokenOptions { Nonce = expectedNonce });
// id.Subject: the stable user ID. Never an email.
// id.TenantId: your own tenant ID for the organization, as you set it when you created the organization.
// id.OrgId and id.MembershipEpoch: keep the highest MembershipEpoch seen per (Subject, OrgId); a lower one is stale.
// epochs is your own store: RecordHighestAsync saves the value and returns false when a higher one is already stored.
if (!await epochs.RecordHighestAsync(id.Subject, id.OrgId, id.MembershipEpoch))
throw new InvalidOperationException("stale membership: sign in again"); // fail closed: do not create the session
await sessions.CreateAsync(id.Subject, id.TenantId, id.SessionId);The verifier checks the signature (RS256 or ES256), iss, aud, exp, nbf and iat with a 60-second clock skew, the nonce, and the organization claims. Every failure is an AuthVertexException with a stable Code. A verified token proves who the user is. What the user may do in your product is your own decision.
To protect an API with AuthVertex access tokens instead, builder.Services.AddAuthVertexAuthentication(o => { o.Issuer = …; o.Audience = …; }) registers the authentication handler and requires an authenticated user on every endpoint unless it opts out with AllowAnonymous.

Back-channel logout
app.MapAuthVertexBackChannelLogout(new LogoutHandler(new LogoutVerifier { Issuer = issuer, Audience = clientId, Keys = keys })
{
// End every local session with this session ID, or every session of the subject when it has none.
OnLogout = (token, ct) => sessions.EndAsync(token.SessionId, token.Subject, ct),
}); // POST /auth/backchannel-logout, anonymous: the logout token authenticates the senderThe endpoint answers 200, or 400 with a JSON OAuth error, always with Cache-Control: no-store. If OnLogout throws, the token is released so the retry is accepted. A token you already processed is answered 200 without calling you again (AuthVertex is retrying after a lost 200); while its first delivery is still running, a repeat gets 503 with Retry-After. MemoryReplayCache protects one process, so with several replicas implement IReplayCache on a shared store and set LogoutVerifier.Replay.
Webhooks: verify, then parse
Webhook endpoints are signed with scheme v2 by default: AuthVertex signs each delivery and you verify it with AuthVertex's published public keys, so you hold no shared secret. The signature is bound to your endpoint ID, which you receive when you register the endpoint.
using AuthVertex.Events;
var applicationId = Guid.Parse(app.Configuration["AuthVertex:ApplicationId"]!);
// AuthVertex's webhook signing keys. Old and new keys overlap during a rotation: reload them at most every five minutes.
using var http = new HttpClient();
var signingKeys = await http.GetStringAsync($"{app.Configuration["AuthVertex:ApiUrl"]}/v1/webhook-signing-keys");
app.MapAuthVertexWebhooks(new WebhookHandler
{
Ed25519Keys = Webhook.KeysFromJwks(signingKeys),
EndpointId = app.Configuration["AuthVertex:WebhookEndpointId"],
RequireV2 = true, // refuse deliveries without a v2 signature
OnEvent = async (verified, ct) =>
{
// The signature, timestamp window and event ID were checked; duplicates never reach this point.
LifecycleEvent evt;
try
{
evt = LifecycleEventParser.Parse(verified.Raw);
}
catch (EventFormatException e) when (e.Code == EventFormatError.UnknownEventType)
{
return; // a newer type: acknowledge, ignore
}
if (evt.ApplicationId != applicationId) return;
switch (evt)
{
case MembershipRevocationEvent r: // suspended, deprovisioned, session revoked
await sessions.EndAllForMembershipAsync(r.MembershipId, ct);
break;
case MembershipUpdatedEvent u when u.Changed.Contains("roles"):
await roles.RefreshAsync(u.MembershipId, ct); // role values are never sent
break;
}
},
}); // POST /webhooks/authvertex, anonymous, raw body
app.Run();The endpoint answers 401 for a bad signature, 400 for a malformed body, 413 when the body is too large, 200 for a duplicate (OnEvent is not called twice) and 500 when OnEvent throws, including an EventFormatException for a malformed event. Return only once the change is stored: AuthVertex retries anything but a 2xx. With several replicas, set a shared Dedupe cache.
After you have enforced a suspension, deprovisioning or session revocation, report it with Acknowledge revocation, using the event's RevocationId.
Endpoints that keep a shared secret (scheme v1 or v1+v2) set Keys = new Dictionary<string, byte[]> { [kid] = secret } instead of, or next to, Ed25519Keys.
Errors
Every rejection is an AuthVertexException with a stable Code, the same in every AuthVertex SDK. keys_unavailable means the issuer's keys could not be fetched: the authentication handler answers 503, never success. See Error codes.
Next steps
- Run the flow end to end in the sandbox.
- Test your logout and webhook endpoints with the conformance kit.
- The integration guide covers client registration, claims and webhooks in full.