Home / Developers / Quickstarts / Go
Quickstart: Go
Verify the sign-in token, handle back-channel logout, and verify then handle lifecycle webhooks with the Go SDK (module path announced at release). Go 1.26 or newer.
Install
Coming — available at release. The module path of the Go SDK is announced at release; the examples import it as authvertex:
go get <module path announced at release>The SDK verifies ID and access tokens, back-channel logout tokens and webhook signatures, and includes net/http middleware and receivers. It uses the standard library only and needs Go 1.26 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
import (
"context"
"io"
"log"
"net/http"
"os"
authvertex "<module path announced at release>"
)
ctx := context.Background()
issuer := os.Getenv("AUTHVERTEX_ISSUER")
clientID := os.Getenv("AUTHVERTEX_CLIENT_ID")
// The issuer's signing keys, found through OIDC discovery. Cached, and refreshed when a token names a new key.
jwksURI, err := authvertex.DiscoverJWKSURI(ctx, nil, issuer)
if err != nil {
log.Fatal(err)
}
keys := &authvertex.RemoteJWKS{URL: jwksURI}
tokens := &authvertex.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, err := tokens.VerifyIDToken(ctx, idToken, authvertex.IDTokenOptions{Nonce: expectedNonce})
if err != nil {
return err // fail closed: authvertex.CodeOf(err) gives the stable code
}
// claims.Subject: the stable user ID. Never an email.
// claims.TenantID: your own tenant ID for the organization, as you set it when you created the organization.
// claims.OrgID and claims.MembershipEpoch: keep the highest MembershipEpoch seen per (Subject, OrgID); a lower one is stale.
// epochs is your own store: RecordHighest saves the value and reports false when a higher one is already stored.
fresh, err := epochs.RecordHighest(ctx, claims.Subject, claims.OrgID, claims.MembershipEpoch)
if err != nil || !fresh {
return errStaleMembership // fail closed: do not create the session
}
return sessions.Create(ctx, claims.Subject, claims.TenantID, claims.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 *authvertex.Error 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, wrap your handlers with authvertex.RequireAuth(resourceVerifier) and read the identity with authvertex.ClaimsFromContext.

Back-channel logout and 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.
res, err := http.Get(os.Getenv("AUTHVERTEX_API_URL") + "/v1/webhook-signing-keys")
if err != nil {
log.Fatal(err)
}
jwks, err := io.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
}
signingKeys, err := authvertex.WebhookKeysFromJWKS(jwks)
if err != nil {
log.Fatal(err)
}
applicationID := os.Getenv("AUTHVERTEX_APPLICATION_ID")
mux := http.NewServeMux()
authvertex.Endpoints{
Logout: &authvertex.LogoutHandler{
Verifier: &authvertex.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: func(ctx context.Context, t *authvertex.LogoutToken) error {
return sessions.End(ctx, t.SessionID, t.Subject)
},
},
Webhooks: &authvertex.WebhookHandler{
Ed25519Keys: signingKeys,
EndpointID: os.Getenv("AUTHVERTEX_WEBHOOK_ENDPOINT_ID"),
RequireV2: true, // refuse deliveries without a v2 signature
// The signature, timestamp window and event ID were checked; duplicates never reach OnEvent.
OnEvent: func(ctx context.Context, e *authvertex.Event) error {
if e.ApplicationID != applicationID {
return nil
}
switch e.Type {
case "membership.suspended", "membership.deprovisioned", "session.revoked":
return sessions.EndAllForMembership(ctx, e.MembershipID)
}
return nil // other types, including types newer than your code: acknowledge
},
},
}.Mount(mux) // POST /auth/backchannel-logout and POST /webhooks/authvertex- Logout: 200 after
OnLogoutreturns, 400 with a JSON OAuth error otherwise, alwaysCache-Control: no-store. IfOnLogoutfails, 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 withRetry-After. - Webhooks: 401 for a bad signature, 400 for a malformed body, 413 when the body is too large, 200 for a duplicate (
OnEventis not called twice), 500 whenOnEventreturns an error. Return only once the change is stored: AuthVertex retries anything but a 2xx. MemoryReplayCacheprotects one process. With several replicas, implementReplayCacheon a shared store and setLogoutVerifier.ReplayandWebhookHandler.Dedupe.
There is no typed events package for Go yet: Event carries the envelope fields, MembershipID, LifecycleEpoch and RevocationID, and Event.Raw holds 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 e.RevocationID.
Endpoints that keep a shared secret (scheme v1 or v1+v2) set Keys: map[string][]byte{kid: secret} instead of, or next to, Ed25519Keys.
Errors
Every failure is an *authvertex.Error with a stable Code (errors.Is(err, authvertex.ErrExpired)), the same in every AuthVertex SDK. keys_unavailable means the issuer's keys could not be fetched: the middleware 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.