Skip to Content
Xeonr Developer Docs
Guides

Protecting a Service

Verify access tokens in your resource server, and refuse the ones that have been revoked since they were signed.

Your service receives a bearer token and has to answer two questions: is this token real, and is it still good. The first is a signature check you can do locally. The second is not, and this guide is mostly about why.

Use an SDK if you can — @xeonr/auth for TypeScript, go-platform/authn for Go. Both do everything below. The manual integration section is for other languages.

Before you start

You need three things from your application's settings in the Xeonr Auth portal:

Issuerhttps://auth.xeonr.io
Audienceyour application's identity audience, urn:xeonr:auth:application:{id}, plus any audience you configured. A token must carry one of yours.
Client credentialsa client id and secret belonging to your application. Only needed for the revocation feed.

Never accept a token without checking aud. A verifier that accepts any audience accepts tokens minted for a different product — including one whose operator is not you.


TypeScript

npm install @xeonr/auth
import { createVerifier, InvalidTokenError, RevokedTokenError } from "@xeonr/auth";

const auth = createVerifier({
  issuer: "https://auth.xeonr.io",
  audiences: ["urn:xeonr:auth:application:42"],
});

app.use(async (req, res, next) => {
  try {
    req.principal = await auth.verifyHeader(req.headers.authorization);
    next();
  } catch (err) {
    if (err instanceof RevokedTokenError) {
      // Valid token, access withdrawn. Let the client refresh.
      return res.status(401)
        .set("WWW-Authenticate", 'Bearer error="invalid_token"')
        .end();
    }
    if (err instanceof InvalidTokenError) return res.status(401).end();
    next(err);
  }
});

req.principal carries subject, scopes, teams, groups, organisationId, authorisationId and the raw claims.

Authorising

import { satisfiesScope } from "@xeonr/auth";

if (!satisfiesScope(req.principal, "myapp:files:edit")) {
  return res.status(403).end();
}

satisfiesScope applies the platform's implication rule: within one product:resource family, admin implies edit implies read. Any other verb matches exactly, and a scope that is not three colon-separated parts is compared exactly — so auth:console is never satisfied by anything else.


Go

go get git.prod.wtf/xeonr/go-platform@latest
verifier, err := authn.NewVerifier(authn.Config{
    Issuer:    "https://auth.xeonr.io",
    Audiences: []string{"urn:xeonr:auth:application:42"},
})

authn ships a Connect interceptor and net/http middleware that put the Principal on the request context. Principal.Satisfies is the same implication rule as above.


Revocation

Everything so far is local: your service verifies a signature and never calls Xeonr Auth. That is the point — no round trip on the request path, and no dependency on the IdP being reachable.

The cost is that your service cannot see anything that happened after the token was signed. Not a logout. Not a disabled account. Not a withdrawn admin role. Without the feed below, a token stays good until it expires — an hour for an ordinary access token, and never for one issued under auth:forever or to a service account.

The revocation feed closes that window. Your service polls it in the background, keeps what it learns in memory, and the check on the request path is a map lookup.

Enabling it — TypeScript

import { createVerifier, RevocationFeed } from "@xeonr/auth";

const revocation = new RevocationFeed({
  issuer: "https://auth.xeonr.io",
  clientId: process.env.AUTH_CLIENT_ID!,
  clientSecret: process.env.AUTH_CLIENT_SECRET!,
  onError: (err) => log.warn({ err }, "revocation feed"),
});
revocation.start();

const auth = createVerifier({
  issuer: "https://auth.xeonr.io",
  audiences: ["urn:xeonr:auth:application:42"],
  revocation,
});

Enabling it — Go

feed, err := authn.NewRevocationFeed("https://auth.xeonr.io", authn.RevocationConfig{
    ClientID:     os.Getenv("AUTH_CLIENT_ID"),
    ClientSecret: os.Getenv("AUTH_CLIENT_SECRET"),
    OnError:      func(err error) { log.WithError(err).Warn("revocation feed") },
})
feed.Start(ctx)

verifier, err := authn.NewVerifier(authn.Config{
    Issuer:     "https://auth.xeonr.io",
    Audiences:  []string{"urn:xeonr:auth:application:42"},
    Revocation: feed,
})

That is the whole integration. Verification now fails with RevokedTokenError (TypeScript) or authn.ErrRevoked (Go) for a token whose access is gone.

Handle "revoked" differently from "invalid"

This is the one thing worth getting right.

A revoked token is well-formed and correctly signed. The subject is still who they say they are; only their access changed. A client holding a refresh token can almost always get a working token without the user doing anything.

So answer 401 with WWW-Authenticate: Bearer error="invalid_token" and let the client refresh. Do not start a new sign-in on this alone — you will bounce a user through a login screen they did not need, every time somebody adjusts a role.

The TypeScript error carries err.reason, one of:

reasonwhat happened
entitlements-changeda team, enrollment or role behind the token's scopes was withdrawn
session-revokedthat specific session was ended — a logout, or a refresh-token reuse
credential-changea password reset or forced logout killed everything issued before it

What it costs

One HTTP request per process every ten seconds, regardless of traffic. On the request path, a map lookup.

Memory is bounded by the revocation rate, not by your user count: a receiver only has to remember a revocation for as long as a token signed before it could still be presented. Everything older is already refused on exp.

Every replica polls independently. The cost scales with pod count, not with the number of services.

How it fails, and the alarm you must set

The feed fails open on its own failures and closed on what it knows. An unreachable feed leaves tokens verifying exactly as they did before; a revocation it has already seen is enforced until it ages out.

This is deliberate — failing closed would turn a blip at the IdP into an outage in every service that integrates. But it means a broken feed looks exactly like a working one: verification keeps succeeding, silently, without revocation.

Set onError / OnError and alarm on it. Nothing else will tell you the feed has been down for six hours.

What you are told about

Only subjects that hold a live grant to one of your application's clients. You will not see revocations for people who have never used your product.


Manual integration

If there is no SDK for your language.

Verifying

  1. Fetch the JWKS from https://auth.xeonr.io/.well-known/jwks.json. Cache it; refetch when you meet an unknown kid, rate-limited so a flood of garbage kids cannot hammer the IdP.
  2. Verify the signature with the key matching the token's kid.
  3. Pin the algorithm to RS256. Do not trust the alg header to choose.
  4. Check iss is exactly https://auth.xeonr.io, aud contains one of yours, and exp is in the future.

See Access Token Anatomy for every claim.

Polling the feed

POST /api/v1/oauth/revocation-events HTTP/1.1
Host: auth.xeonr.io
Authorization: Basic {base64(client_id:client_secret)}
Content-Type: application/json

{"cursor": "{the cursor from your last response}"}

The endpoint is published as revocation_events_endpoint in the discovery document.

{
  "sets": { "{jti}": "{a signed Security Event Token}" },
  "cursor": "...",
  "moreAvailable": false,
  "retentionSeconds": 7200
}

Each value in sets is an RFC 8417 Security Event Token carrying a CAEP event:

{
  "iss": "https://auth.xeonr.io",
  "jti": "...",
  "iat": 1761000000,
  "aud": "{your client id}",
  "sub_id": { "format": "uri", "uri": "urn:xeonr:auth:uid:user:12" },
  "events": {
    "https://schemas.openid.net/secevent/caep/event-type/token-claims-change": {
      "event_timestamp": 1761000000,
      "claims": { "urn:xeonr:auth:teams_version": 7 }
    }
  }
}

Three event types, and what each means for a token you hold:

eventreject the token when
.../token-claims-changeits urn:xeonr:auth:teams_version is below the epoch in claims. No epoch claim on the token? Compare its iat against event_timestamp instead — that over-rejects slightly and never under-rejects.
.../session-revokedits urn:xeonr:auth:authorisation_id equals the event's sid. These are the same value by design, which is what lets one logout kill one session rather than all of them.
.../credential-changeits iat is before event_timestamp. Nothing survives a credential change.

Ignore event types you do not recognise rather than failing the batch, so a new one does not break you.

Rules for a correct receiver

  • Start with no cursor. The first poll returns nothing and a cursor pinned to now. That is correct: you cannot be holding a token minted before you had a cursor.
  • Deduplicate on jti. The feed deliberately re-reads an overlap window, so the same event arrives several times.
  • Keep the highest epoch per subject, not the latest arrival. Events can arrive out of order; taking the most recent one would let an older epoch undo a newer one.
  • Drain on moreAvailable rather than waiting out your interval — the backlog is revocations you are not yet enforcing.
  • Expire entries older than retentionSeconds. That is what keeps your memory bounded.
  • On {"error": "cursor_expired"}, drop your cursor and start again — and log it loudly. There is a gap behind it that no response can fill, and resuming quietly would leave you believing you were caught up.
  • Do not fail closed when the feed is unreachable.

You do not need to verify the SETs' signatures. They arrive over TLS from an endpoint authenticated with your own client credentials, and every event can only ever remove access — a forged one costs a refresh, not an escalation. Verifying adds a second JWKS path whose failure modes silently stop revocation.

Deviations from RFC 8936

The feed is Shared Signals poll delivery, with two deliberate differences. Both follow from the events being idempotent, and both are handled for you by the SDKs:

  1. Acknowledgement is a cursor you hold, not per-event ack state the transmitter keeps.
  2. That cursor is a timestamp read with an overlap, not a sequence — which is why you must deduplicate on jti.

On this page