Home / Developers / Quickstarts / Java
Quickstart: Java
Verify the sign-in token, handle back-channel logout, and verify then handle lifecycle webhooks with com.authvertex:authvertex-sdk. Java 17 or newer.
Install
Coming — available at release. When the SDK is released, you will add it with these coordinates; the version is announced at release:
<dependency>
<groupId>com.authvertex</groupId>
<artifactId>authvertex-sdk</artifactId>
<version><!-- announced at release --></version>
</dependency>The SDK verifies ID and access tokens, back-channel logout tokens and webhook signatures. It needs Java 17 or newer and has no runtime dependencies: cryptography is the JDK's, HTTP is java.net.http. A Jakarta Servlet filter, receiver servlets and Spring Boot auto-configuration are in a separate module.
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
import com.authvertex.sdk.*;
String issuer = System.getenv("AUTHVERTEX_ISSUER");
String clientId = System.getenv("AUTHVERTEX_CLIENT_ID");
// The issuer's signing keys, found through OIDC discovery. Cached, and refreshed when a token names a new key.
RemoteJWKS keys = RemoteJWKS.discover(issuer);
TokenVerifier tokens = new TokenVerifier(issuer, clientId, 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 = tokens.verifyIdToken(idToken, expectedNonce); // throws AuthVertexException
// id.getSubject(): the stable user ID. Never an email.
// id.getTenantId(): your own tenant ID for the organization, as you set it when you created the organization.
// id.getOrgId() and id.getMembershipEpoch(): keep the highest getMembershipEpoch() seen per (subject, organization); a lower one is stale.
// epochs is your own store: recordHighest saves the value and returns false when a higher one is already stored.
if (!epochs.recordHighest(id.getSubject(), id.getOrgId(), id.getMembershipEpoch())) {
throw new IllegalStateException("stale membership: sign in again"); // fail closed: do not create the session
}
sessions.create(id.getSubject(), id.getTenantId(), id.getSessionId());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 getCode(). A verified token proves who the user is. What the user may do in your product is your own decision.
Back-channel logout
// End every local session with this session ID, or every session of the subject when it has none.
LogoutHandler logout = new LogoutHandler(new LogoutVerifier(issuer, clientId, keys),
t -> sessions.end(t.getSessionId(), t.getSubject()));
// The JDK HTTP server:
server.createContext("/auth/backchannel-logout", logout.asHttpHandler());
// Any other framework: HandlerResponse r = logout.handle(method, contentType, body);The handler answers 200, or 400 with a JSON OAuth error, always with Cache-Control: no-store. If your callback 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; with several replicas, implement ReplayCache on a shared store and set it with LogoutVerifier.replayCache(...).
Webhooks: verify, then handle
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.
// AuthVertex's webhook signing keys. Old and new keys overlap during a rotation: reload them at most every five minutes.
HttpClient http = HttpClient.newHttpClient();
String jwks = http.send(
HttpRequest.newBuilder(URI.create(System.getenv("AUTHVERTEX_API_URL") + "/v1/webhook-signing-keys")).build(),
HttpResponse.BodyHandlers.ofString()).body();
String applicationId = System.getenv("AUTHVERTEX_APPLICATION_ID");
WebhookHandler webhooks = new WebhookHandler()
.ed25519Keys(Webhooks.webhookKeysFromJwks(jwks))
.endpointId(System.getenv("AUTHVERTEX_WEBHOOK_ENDPOINT_ID"))
.requireV2(true) // refuse deliveries without a v2 signature
.onEvent(event -> {
// The signature, timestamp window and event ID were checked; duplicates never reach this point.
if (!event.getApplicationId().equals(applicationId)) return;
switch (event.getType()) {
case "membership.suspended", "membership.deprovisioned", "session.revoked" ->
sessions.endAllForMembership(event.getMembershipId());
default -> { } // other types, including types newer than your code: acknowledge
}
});
server.createContext("/webhooks/authvertex", webhooks.asHttpHandler());The handler answers 401 for a bad signature, 400 for a malformed body, 413 when the body is too large, 200 for a duplicate (your callback is not called twice) and 500 when your callback throws. Return only once the change is stored: AuthVertex retries anything but a 2xx. Other frameworks call webhooks.handle(method, signatureHeader, eventIdHeader, body).
There is no typed events package for Java yet: WebhookEvent carries the envelope fields, getMembershipId(), getLifecycleEpoch() and getRevocationId(), and getRaw() returns the whole verified body. Every field is listed in the webhook event catalog.
After you have enforced a suspension, deprovisioning or session revocation, report it with Acknowledge revocation, using getRevocationId().
Endpoints that keep a shared secret (scheme v1 or v1+v2) call .keys(Map.of(kid, secret)) instead of, or next to, .ed25519Keys(...).
Errors
Every failure is an AuthVertexException with a stable getCode() (ErrorCode.EXPIRED.code() is "expired"), the same in every AuthVertex SDK. keys_unavailable means the issuer's keys could not be fetched: treat it as a temporary failure, never as 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.