Skip to main content

Sign in with Ward (OpenID Connect)

Every app keeps its own accounts and its own login page. "Sign in with Ward" is an extra button on that page: an OpenID Connect authorization code flow with PKCE, against Ward as the provider. Ward runs oidc-provider rather than a hand-written protocol. The design and what it replaced are in the corpus page decisions-oidc.

This page is the integration contract. The client side of all of it (the code flow, the ID token check, the 30-second /session-status cache, /notify) is built into the shared library each app vendors; its adoption guide is shared-library/README.md in the repo. The shared-cookie contract that came before (/introspect, app keys, the access cookie at Path=/) was retired on 2026-10-13.

The issuer​

WARD_OIDC_ISSUER is the issuer as the browser sees it, for example https://example.com/ward-api/oidc. It must end in /oidc, Ward's internal mount. Whatever precedes /oidc is the prefix the proxy strips: /ward-api behind Caddy, nothing when a client talks to Ward directly.

Pick the prefix with care

oidc-provider finds its mount by looking for the request's own path inside the full one. A prefix that itself contains /auth, /token, /jwks, /me, /request or /session would make every advertised URL wrong. /ward-api, and a subdomain with no prefix at all, are both safe.

Every URL the provider advertises is built from that value and never from the request, so discovery, iss and every endpoint name the external URL. A request's own Host and X-Forwarded-* headers cannot change them.

EndpointThe browser or app uses (issuer …/ward-api/oidc)Ward serves internally
Discovery/ward-api/oidc/.well-known/openid-configuration/oidc/.well-known/openid-configuration
JWKS/ward-api/oidc/jwks/oidc/jwks
Authorization/ward-api/oidc/auth/oidc/auth
Token/ward-api/oidc/token/oidc/token
End session/ward-api/oidc/session/end/oidc/session/end
Login step/ward-api/refresh/oidc/<uid>/refresh/oidc/<uid>

The JWKS publishes Ward's existing Ed25519 key, the same kid as /ward-api/.well-known/jwks.json. Userinfo, dynamic registration, PAR, introspection and revocation are off.

What the flow allows​

  • Grant: authorization_code only. No implicit flow, no password grant, no refresh tokens.
  • PKCE: required, S256 only.
  • Response type: code. Scope: openid.
  • Signatures: Ed25519 throughout. ID tokens are signed EdDSA; pin alg to EdDSA when verifying, and give openid-client the client metadata id_token_signed_response_alg: "EdDSA", or it expects RS256. A client assertion may say EdDSA or Ed25519; openid-client 6 sends Ed25519.

Clients are apps​

client_id is the app's slug. In the console, open Apps, then the app, then Sign in with Ward, and set:

  • Redirect URIs, one per line, compared as exact strings. Register one per environment: the dev server's (plain http is allowed on localhost) and the production one (https).
  • Sign-out return URIs, where Ward may send someone after "sign out of Ward too".
  • The app's public key, a JWK.

An app with no redirect URI or no key is not a client, and Ward answers invalid_client. The local seed registers each app with its dev redirect URI (<dev origin><API prefix>/auth/ward/callback, for example http://localhost:5173/atrium-api/auth/ward/callback). The callback sits under the app's API prefix because a link callback needs the app's session cookie, which is scoped to that path.

How an app authenticates: private_key_jwt​

Ward stores no app secret. Each app holds an Ed25519 private key in its own environment and signs a short client assertion with it at the token endpoint. Ward holds only the public JWK.

Make a pair with:

npm run oidc-client-key --workspace=api -- <app-slug>

It prints two things and writes nothing:

  1. WARD_OIDC_CLIENT_KEY=… for the app's environment. The value is the private JWK (kty, crv, x, d, kid, use) as JSON, base64url-encoded.
  2. The public JWK, one JSON line, for the console. Ward refuses a key that carries d.

The assertion is a compact JWS with header alg EdDSA or Ed25519 and the key's kid (required once a rotation registers two keys), and these claims:

ClaimValue
iss, subthe client_id
audthe issuer (the token endpoint URL is also accepted)
expa short time ahead
jtifresh every time; a reused one is refused

openid-client's PrivateKeyJwt builds exactly this. To rotate, register the new public key next to the old one (paste {"keys":[old, new]}), deploy the new private key, then remove the old one.

The login step​

The provider sends every authorization to Ward's login step, and the step asks Ward's refresh cookie, not the provider's own session:

  • A live Ward session finishes the step with no password prompt.
  • Otherwise the person sees Ward's login page, headed "Continue to" the app's display name. Signing in there makes an ordinary Ward session.
  • The account must be active and hold a grant for the client's app. If not, the app receives error=access_denied at its redirect URI.
  • "Back to the app" on the login page also returns access_denied.
  • There is never a consent screen.
  • prompt=login and max_age ask for a password typed recently, not just a live session.

A wrong or unregistered redirect URI is never redirected to. Ward shows its own error page instead, because sending an error to an unregistered URI would be an open redirect.

The ID token​

ClaimTypeValue
issstringthe issuer
audstringthe client_id
substringthe Ward subject, unchanged
preferred_usernamestringthe Ward username
ward_sidstringthe Ward session: the refresh family id
ward_rolestringa role the account holds in this app (the first, sorted, if it holds several)
nonce, iat, expstandard; auth_time too when max_age is sent

Email is never included. ward_sid is the id an app keeps on its own session row and asks Ward about. The provider's own sid claim is not used.

Asking whether a Ward session is still live​

A session that began with "Sign in with Ward" ends within 30 seconds of a Ward sign-out, a console revoke, a password change or a removed grant. The app keeps the ID token's ward_sid on its own session row and asks Ward. Sessions that began with a local password are never asked about.

POST /ward-api/session-status (Fastify sees /session-status), JSON body:

{
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": "<a fresh client assertion, aud = the issuer>",
"wardSid": "<the ID token's ward_sid>",
"subject": "<the ID token's sub>"
}

The first two fields are the standard form of private_key_jwt, the same assertion the app signs for the token endpoint, with the issuer as aud. Sign a new one for every call: its jti is spent on use, and Ward shares the markers with the token endpoint, so a reused assertion is refused wherever it is presented.

AnswerMeaning
200 {"active":true,"role":"<role>"}The Ward session is live and is this subject's, the account is active, and the account holds a grant in this app. role is the one ward_role carries.
200 {"active":false}Anything else: a revoked, expired or unknown session, a disabled account, a subject that is not the session's, no grant in this app, a malformed body. Ward never says which.
401 {"error":"invalid_client"}The assertion is missing or does not verify: no assertion, the wrong type, an unknown client, a wrong key, audience or expiry, or a reused jti.

The app is always the assertion's client. A body cannot name another app's grants, and there is nothing to configure. Without WARD_OIDC_ISSUER, Ward does not mount the route at all, and the answer is 404. The call is not audited and not rate limited, because every Ward-originated session of every app makes it every 30 seconds.

The app's side:

  1. Cache each answer for 30 seconds per wardSid, in process, and ask again only after that. The 30 seconds is the longest a revoked session survives, so a longer cache breaks the promise.
  2. Collapse concurrent calls. While one call for a wardSid is in flight, every other request for it waits for that answer instead of sending its own.
  3. Fail closed. A timeout, a network error, any status other than 200, or a body that is not { "active": boolean } means the Ward-originated session is rejected, and the person is told to sign in with their local password. Never treat an error as "still live", and do not cache a failure as an answer.
  4. A 401 is its own error. It does not mean the person signed out. It means the app's client key, client_id, or the issuer it signs for is wrong, so every Ward-originated session of the app fails at once. Log it as a configuration error naming the client, and keep failing closed.

Mailing a user: POST /notify​

POST /ward-api/notify takes the same credential: put client_assertion_type and client_assertion in the JSON body beside subject, mailSubject and text. Ward mails the subject's address, which the app never sees. A missing or bad assertion is the same 401 {"error":"invalid_client"}. The old x-ward-app-key header no longer authenticates anything.

Logout​

An app that wants "sign out of Ward too" sends the browser to the end-session endpoint with id_token_hint (the ID token it received), and optionally post_logout_redirect_uri (registered) and state. Ward revokes the Ward session named by ward_sid, exactly as POST /logout would, and sends the browser back. Without id_token_hint, nothing at Ward is revoked.

Environment variables​

VariableNotes
WARD_OIDC_ISSUEROptional. Unset, the provider is not mounted. Must end in /oidc.
WARD_UI_URLRequired with the issuer. Ward's UI, absolute, on the issuer's origin; the login page is <this>/login.

On the app's side the local seed writes WARD_OIDC_ISSUER, WARD_OIDC_CLIENT_ID, WARD_OIDC_CLIENT_KEY, WARD_OIDC_REDIRECT_URI and the optional WARD_OIDC_POST_LOGOUT_REDIRECT_URI.