Skip to content

tdacorp-identity

tdacorp-identity is a self hosted authentication server: OpenID Connect, passkeys, Cedar permissions and security rules written as named tests.

On this page

Every product with users wants a front door. Build that door once per product and you end up with a row of them, each with its own lock, its own bugs and its own opinion about who you are. tdacorp-identity is the single door instead: a self hosted authentication server that TDACorp, my company, builds its products against. It signs people in, speaks OpenID Connect, and answers the harder question that arrives right after sign-in. Now that you’re inside, what are you allowed to touch?

The repository’s history starts on 14 August 2026. The code in it had been copied wholesale out of v3, a site builder of mine, and it brought luggage: organisations, billing, a media library. All of that was cut. A bouncer doesn’t need to run the gift shop.

One front door, five programs

The workspace splits the job into pieces that each do one thing:

ProgramIts job
identitydThe headless provider: protocol endpoints, sign-in, account and admin APIs, background workers
Web app (Next.js)Renders the sign-in and account pages, and mounts the provider inside its own process
Admin consoleThe screens for whoever runs the place
idctlThe operator’s tool at a terminal
Browser suite (Playwright)Drives a real browser through the flows

The first two are separate programs in the source and one deployment when shipped. It’s TypeScript on Node 24, a pnpm workspace, with Postgres underneath. The libraries live in their own packages, and one of them exists only to be the typed contract between the pages and the provider. If the two disagree, the compiler hears about it first.

What a self hosted authentication server speaks

People get passkeys, passwords hashed with Argon2id, and time based one time codes. Passkeys are registered as discoverable credentials with user verification required, and the sign-in field uses the browser’s conditional interface, so a saved passkey is offered right from the field’s autofill list.

Applications get the strict end of OAuth and OpenID Connect:

MechanismWhat it does
Authorization code with PKCEOnly the hashed S256 method
Pushed authorization requestsThe request reaches the server before the browser is redirected anywhere
Signed client assertionsA client proves itself with a signature
DPoPA token is tied to a key the client holds
Redirect addressesAn exact match
Refresh tokensThey rotate, and a spent one is watched

Token exchange is there too, along with back-channel logout, so products hear about a sign-out from the source.

That last table row is my favourite, because networks are clumsy. A client can lose a reply and ask again in all innocence, so the server has a rule for a spent token coming back.

An honest retry costs nothing. Outside one, the whole family goes down, and the session goes with it.

Permissions that travel with the token

Knowing who someone is gets you nowhere until something decides what they can do. That decision runs on Cedar, a policy language with its official evaluator compiled to WebAssembly. The code around it is a set of pure functions with no database handle. It can decide on the facts it’s handed and nothing else, which means a policy can’t wander off and fetch itself a more convenient answer.

The order of the decision is short enough to draw:

flowchart TD
    Q["Who, which action, which resource"] --> L{"Facts loaded and evaluated?"}
    L -- no --> I["Indeterminate: not a yes"]
    L -- yes --> F{"Any forbid matches?"}
    F -- yes --> D["Deny"]
    F -- no --> G{"A grant or permit matches?"}
    G -- yes --> A["Allow"]
    G -- no --> D

Notice that the forbid is asked before anything gets a chance to say yes, and that indeterminate is its own answer, settled by rules declared per permission. Every answer carries a reason code. For a high risk action, indeterminate resolves to deny, because “I don’t know” is a poor reason to open a door.

Products don’t have to phone home for each click. The permission codes ride inside the access token, and the product checks them locally. The same decision engine builds that claim, so a forbid applies there exactly as it does anywhere else.

Rules the test suite refuses to forget

The specification lists nineteen invariants, and each is tied to a named test. A few in plain words: nobody can hand out more access than they hold. Inside the decision engine, a revoked grant never matches again, even while a cache still remembers saying yes. An access token has exactly one audience.

A list like that rots quietly. Someone renames a test, skips another on a bad afternoon, and the document keeps smiling. So a register file maps each invariant to a test file and an exact test title, and a script reads those files with the TypeScript compiler’s own parser. It fails when a file or title is gone, and when the test, or any block wrapped around it, is marked skip, todo or only. A title sitting in a comment doesn’t count. I’ve written before about trusting but verifying; this is the version with a parser.

A database that keeps its own rules

One design principle in the spec is to assume a second code path exists and make the database enforce the invariant anyway. Today’s code behaves. The script somebody writes at midnight next year hasn’t promised anything.

The schema is numbered SQL files, applied in order and frozen once applied. The ORM’s migration generator isn’t installed in any package, and a test fails if someone adds it. The audit log is hash chained, and a trigger checks that each new row extends the chain properly and refuses edits to old ones.

Performance gets the same treatment. A test runs the real application, counts the SQL statements behind the busiest requests and holds each one to a budget. A millisecond threshold on a shared database is a coin toss. A statement count is arithmetic. Add one query to a hot path and the build asks you to come and explain yourself.

Rewriting it without asking anyone to start over

The current design was specified on 7 September 2026 and scaffolded the same day, as an independent workspace in a subfolder, so the first generation kept building while its replacement grew beside it. On 29 September the import learned the two things that matter to a person with an account: keep their user ID, and verify their old password hash unchanged. Nobody should have to reset a password because the architecture got nicer.

On 4 October one commit deleted the first generation: 913 files and 145,044 lines. It stays reachable under a tag, which is where old code belongs. Visible if you go looking, and out of everybody’s way.

The SDK, and where this stands

Products talk to the server through @tdacorp/identity-sdk, published on npm under the MIT licence and at version 3.0.0 as I write. It covers the parts every application would otherwise write badly in a hurry: signing a user in, calling as a service, verifying tokens on an API, checking permissions and sealing the session. My personal site has its sign-in wired through it.

The server itself is proprietary, so there’s no repository link here. Its README still files it as pre-production, and I’ll file it the same way. The door has nineteen rules posted next to it. The interesting work is keeping every one of them true while the building behind it fills up.