A hand-written OIDC provider instead of a library
Status
Section titled “Status”Accepted. The decision was taken one day after ADR 0001 anticipated it, and no OAuth library has been in the dependency list since.
2026-05-28
Context
Section titled “Context”FlowCatalyst is an OAuth 2.0 and OpenID Connect provider. It issues access, refresh and ID tokens
to SDK consumers (client_credentials) and to people (authorization_code with PKCE), and it
publishes discovery and a JWKS document. The first implementation composed a general-purpose OAuth
library for those endpoints.
The platform’s needs pulled against that library’s model:
- Tokens carry platform-specific claims:
tier,scope(granted permissions),clients,roles,applications,all_applicationsandtoken_use. Each is computed from the principal at mint time. - Signing keys rotate, and the JWKS document must publish the current key and the previous one so tokens signed just before a rotation still verify.
- Public clients need PKCE, with rules the platform sets itself (for instance
S256only at/oauth/authorize). - Clients have per-client behaviour: rate limits, application confinement, loopback redirects for a command-line client, and an absolute refresh-family lifetime.
- The wire shape of every endpoint is a contract (see ADR 0003), so the platform needs exact control over status codes, error bodies and headers.
The library was storage-backed and opinionated about sessions and claims. Each platform rule meant bending it through hooks, and ADR 0001 had already shown one place where the shapes simply did not match.
Decision
Section titled “Decision”Write the provider side by hand, one endpoint at a time, and remove the library.
auth/oauthapiserves token, authorize, introspect, revoke and userinfo, plus/.well-known/openid-configurationand the JWKS document.auth/authservicemints and validates the JWTs and builds the JWKS.auth/grantstorepersists authorization codes, refresh tokens and pending-authorisation state in theoauth_oidc_payloadstable.auth/sessiontokenkeeps the cookie path from ADR 0001.
Libraries are still used where they are primitives or a client:
golang-jwt/jwt/v5for JWT encoding and decoding;coreos/go-oidcandgolang.org/x/oauth2for the OIDC bridge, where FlowCatalyst is a client of an external identity provider (see Federation);go-webauthnfor passkeys andx/crypto/argon2for password hashing.
The port was done in a sequence of small commits on one day (foundation, token, introspect and revoke, discovery and JWKS, authorize, then removal), each leaving the tree working.
Consequences
Section titled “Consequences”Good
- Full control of the wire contract and of claim computation, in code that reads top to bottom.
- Multi-key JWKS rotation, the platform’s PKCE rules and per-client limits are ordinary code rather than library extensions.
- A smaller dependency graph for the most security-sensitive part of the platform.
- The one deliberate exception to client credentials (a developer user minting a token as themselves) is an explicit branch in the token handler, re-checked on each mint.
Bad
- The platform owns protocol correctness. A library’s years of review do not come for free, so the platform carries its own security audit and tests of the provider endpoints. Defects found since have been in the platform’s code, such as refresh rotation having to be made atomic.
- New protocol features (for instance a new grant type) are written rather than enabled.
- A reader must know OAuth and OIDC well to review the provider.
Alternatives considered
Section titled “Alternatives considered”- Keep the library and patch around it. Rejected for the reasons above: every platform rule needed a workaround and the storage model did not fit stateless tokens.
- Another OAuth server library. Any storage-backed provider framework has the same shape.
- A separate identity product in front of the platform. This would put claim computation (roles, applications, tier) in a second system that has to read the platform’s data.