Session tokens are owned by sessiontoken
Status
Section titled “Status”Accepted. The OAuth-library half of the original record is moot: it was overtaken by ADR 0002, which removed the library entirely. The package split this record introduced still stands.
2026-05-27
Context
Section titled “Context”The platform signs JWTs in two places that look alike but behave differently:
- OAuth access tokens, returned by
POST /oauth/tokenand checked atPOST /oauth/introspect. These are the machine-to-machine and OpenID Connect surface. - Session-cookie tokens, minted by
POST /auth/login(and by the OIDC bridge callback after a single sign-on round trip), set as thefc_sessioncookie, and validated by the authentication middleware on every later request.
Both paths first went through one third-party OAuth library. The OAuth endpoints fitted it. The cookie path did not. The library assumes every token comes out of a grant flow that writes the token to storage and later validates it by looking it up. A session cookie is a stateless, self-contained JWT minted outside any grant. There is nothing in storage to look up.
The mismatch showed up as workarounds:
- minting a session token meant building a synthetic access request and granting a scope through it,
because the library overwrote the token’s
exp,scopeandaudclaims from the request; - introspecting a token that was not in storage failed early in a way that stopped any stateless validator from running, so adding one beside the storage-backed one did not help.
These were not bugs in the library. It is built to be storage-backed and the cookie path wanted to be stateless.
Decision
Section titled “Decision”Split the JWT layer along the boundary it actually follows.
- The OAuth surface (
/oauth/*, discovery, JWKS) is one component with its own client storage and token strategy. sessiontokenis a small standalone package that handles session-cookie and bearer-token JWTs end to end:MintandValidate, built directly ongolang-jwt/jwt/v5. It depends on nothing else in the authentication area.
Both sign with the same RS256 key pair, so a signature verifies on either side of the line. The
shape of each token is owned in exactly one place. sessiontoken writes the platform’s standard
claim set (iss, sub, iat, exp, nbf, tier, scope, email, clients, roles,
applications) and the middleware reads the same names, so a session token and an OAuth-minted token
are interchangeable to anything downstream. See Tokens and
Tokens and claims.
Consequences
Section titled “Consequences”Good
- Minting and validating a session token are one call each. The package says honestly what it does.
- The authentication middleware needs only a public-key validator, not an OAuth provider object.
- Adding a claim means editing one struct and two functions, with no library session plumbing.
- The package is where token-class rules live.
IsAPICredentialis an allowlist on thetoken_useclaim: anapimarker (or none, for cookies) is admitted and any other value is refused, so a new token class is closed to the API by default.
Bad
- The platform owns session-cookie security: algorithm choice, claim validation and expiry checks. The surface is small and covered by unit and fuzz tests, but it is ours.
- The OAuth endpoints and
sessiontokenmust keep using the same signing key. They do, because both take it from the same source. - The package grew past the “about 120 lines” the first record gave as its size, because later work
added
token_use,all_applications, principal type andiathandling. It remains one file with no dependencies on the rest of the authentication code.
Alternatives considered
Section titled “Alternatives considered”- Keep both paths in the OAuth library. Rejected: it forced a synthetic grant for every cookie and broke stateless introspection.
- Store session tokens like grants. This would have made the cookie path fit the library, at the cost of a database lookup per request and a table to prune. Stateless validation was the point.
- Wait and fix it inside the library. The friction was structural, not a defect, so there was nothing to fix.
- Tokens: token classes, the claims they carry and how they are checked.
- Tokens and claims reference
- ADR 0002: a hand-written OIDC provider
- ADR 0021: id_token as an assertion, access token as a credential