Skip to content

Accept central login tokens in the app API where configured - #923

Merged
rzueger merged 2 commits into
developfrom
claude/magical-dirac-ww38gt
Nov 20, 2026
Merged

rzueger merged 2 commits into
developfrom
claude/magical-dirac-ww38gt

Conversation

@rzueger

@rzueger rzueger commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Small follow-up to #922 for the proof of concept "central login + MCP hub". The Open Digital MCP hub
(odch/mcp-hub) records departures and arrivals for a pilot from an AI client (Claude). It exchanges the
pilot's token at the central login (odch/odch-login, token exchange RFC 8693) for a 5-minute token for
exactly one Flightbox instance and calls the movement routes of #922 with it. This PR lets
functions/api/http/appAuth.js accept those tokens, only where the project config sets centralLogin,
and sets it for lsze test only, pointing to the dev login that now runs in odch-login-dev.

Commits

  1. Accept central login tokens in the app API where configured

    • functions/api/http/loginTokens.js (new): verifies login tokens. ES256 JWT with typ at+jwt, iss =
      the configured issuer, aud = this instance (e.g. flightbox-lsze-test), verified e-mail
      (email, email_verified), scope movements:write, lifetime at most 1 h. Keys come from the login's
      JWKS, cached 10 min, refetched for an unknown kid (at most every 30 s); a failing refetch keeps the
      cached keys.
    • appAuth: with a verifier, tokens whose (unverified) iss is the login go to it; all others go to
      Firebase as before. The actor is the pilot with the token's e-mail (lower-cased), uid
      login:<account id>, never admin, guest or kiosk. A rejected token is 401 (Invalid or expired token),
      unreachable keys are 500, as for Firebase tokens.
    • registerMovementRoutes builds the verifier from config.centralLogin.
    • New setting centralLogin: {issuer, jwksUri, audience} per environment, validated by
      tasks/generateServerConfig.js (dependency-free centralLoginConfig.js, so the deploy can load it before
      the functions' npm ci). Only in the generated config when set. Documented in projects/Configuration.md.
    • jsonwebtoken becomes a direct dependency of functions/ (it is already in the tree through
      firebase-admin; the lockfile only gains the entry). jose would be the usual choice, but it is ESM-only
      and does not load under Jest.
  2. Accept central login tokens on lsze test: projects/lsze.json, environments.test:

    "centralLogin": {
      "issuer": "https://odch-login-422294830636.europe-west1.run.app",
      "jwksUri": "https://odch-login-422294830636.europe-west1.run.app/jwks",
      "audience": "flightbox-lsze-test"
    }

    A spec checks that no other project or environment sets it.

Ownership is unchanged: the domain sets createdBy to the actor's e-mail and the REST adapter writes with
auth_variable_override {uid: "login:…", token: {email}}, so the database rules check auth.token.email
exactly as for a pilot signed in to the app with the same address. The pilot sees and edits the same
movements either way.

Unchanged

  • Database rules, the app, Firebase ID token handling, all other routes.
  • Every project and environment except lsze test.

Test plan

  • npm test: 353 suites / 7794 tests
  • npm run typecheck
  • npm run test:functions: 108 suites / 4561 tests. New: loginTokens.spec.js (algorithm confusion,
    alg: none, wrong type, audience, issuer, expiry, lifetime, unknown/rotated keys, foreign signature,
    missing e-mail/scope, JWKS outage, stale cache), appAuth (actor, 401, 500, Firebase still works,
    never admin even with an /admins entry), movement routes with real tokens (create owned by the pilot,
    update own, 403 for another pilot's movement, 401 for other instance/scope, 401 without config),
    generateServerConfig (emitted only where set, lsze test only, malformed configs rejected).
  • End to end, locally: the real movement routes and verifier of this branch with the real RTDB adapter
    against the database emulator with the built lsze rules, behind the real login and hub; a Claude-like
    MCP client (dynamic registration, PKCE, e-mail code, passkey in Chromium) recorded a departure and an
    arrival (createdBy = pilot's address), patched its arrival, got 403 for another pilot's movement; the
    hub's own token was rejected (401). Harness: odch/mcp-hub e2e/.
  • The dev login is deployed (odch-login-dev) and serves its metadata and JWKS.
  • After merge and the lsze-test deploy: one movement via Claude, then check it in the app with the same
    e-mail address.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EsQwcnrmAeK6sEnrzrGVr4

The MCP hub (odch/mcp-hub) records movements for a pilot. It exchanges
the pilot's token at the central login (odch/odch-login, RFC 8693) for
a short-lived token for exactly one Flightbox instance and calls the
movement routes of the app API with it.

- functions/api/http/loginTokens.js verifies such tokens: ES256 JWT
  (typ at+jwt) from the configured issuer, audience of this instance,
  verified e-mail, scope movements:write, keys from the login's JWKS
  (cached, refetched for an unknown kid).
- appAuth takes them only when a verifier is passed: tokens whose iss
  is the login go there, all others to Firebase as before. The actor
  is the pilot with the token's e-mail, uid "login:<account id>",
  never admin, guest or kiosk. Ownership and the database rules
  (auth.token.email via auth_variable_override) apply unchanged.
- New project setting centralLogin {issuer, jwksUri, audience}, per
  environment, validated by generateServerConfig.js. Not set for any
  project yet: the login runs at a run.app address for now.
- jsonwebtoken (already in the tree through firebase-admin) becomes a
  direct dependency; jose is ESM-only and does not load under Jest.
Sets centralLogin for lsze test to the dev login (odch-login-dev,
europe-west1), so the MCP hub (odch-mcp-hub-dev) can record movements
there for a pilot. Only the functions of lsze-test read it.
@rzueger
rzueger merged commit 18b93ae into develop Nov 20, 2026
2 checks passed
@rzueger
rzueger deleted the claude/magical-dirac-ww38gt branch November 20, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants