feat(auth): optional Ever ID sign-in provider (OpenID Connect)

Merged
EV
16d ago
+4986-21

What

An optional sign-in provider everid: Continue with Ever ID, next to email and password, API clients and Google. It works with Ever ID and with any other OpenID Connect issuer. Traduora keeps issuing its own access tokens; the issuer only proves who signs in.

Off by default. Unless TR_AUTH_EVERID_ENABLED=true: the provider is not listed by GET /api/v1/auth/providers, no button shows, every Ever ID path answers 400 and nothing is requested from the issuer. Password, API client and Google sign-in work exactly as before (the existing e2e suite runs unchanged, and a new test asserts the Google token request body byte for byte).

API

  • providers.everid from TR_AUTH_EVERID_* (see docs/configuration.md). Scopes: openid profile email, plus the organization and Ever Platform audience scopes when TR_AUTH_EVERID_PLATFORM_PROJECT_ID is set. When enabled, one OpenID Connect discovery at boot; incomplete settings, a non-https issuer or a failed discovery leave it off with one warning line, never a crash. An issuer on an Ever host is used only by the Ever-operated cloud (TR_EVER_INSTALL_SOURCE=cloud), decided from the configured URL before any request.
  • OidcProviderService (jose): code exchange with the PKCE verifier (HTTP Basic client authentication, client_secret_post only when the issuer supports nothing else); ID token verification: signature, iss among the accepted issuers (1 to 3, kept exactly as configured), aud/azp, exp, iat, nonce, email_verified === true. Key set cached 600 s, unknown kid refetched at most once per 30 s, stale keys served up to 6 h while the issuer is unreachable (without retrying it for 30 s after a failure). Discovery documents must name the configured issuer and keep their endpoints on its origin.
  • Accounts are found by (issuer, subject) only, in the new user_identity table:
    • connected identity: signed in (no pending invitation is accepted on this path);
    • an account has the same email: 409 account_exists, nothing linked, no token;
    • new person: 409 signup_confirmation_required with a sealed record (AES-256-GCM, key derived from TR_SECRET, 10 min) and the pending invitations; the account is created only by POST /api/v1/auth/everid/signup-confirm, which accepts only the ticked invitations. TR_SIGNUPS_ENABLED=false still means invitation only (403 signup_disabled).
  • Connect from settings: POST /api/v1/auth/identities/connect (needs a sign-in at the issuer within 300 s plus 60 s skew, else 400 reauth_required) answers both emails, POST /api/v1/auth/identities/connect/confirm links (403 for another account, 409 subject_linked when the identity is linked elsewhere). GET /api/v1/auth/identities, DELETE /api/v1/auth/identities/:id (409 last_sign_in_method when the account has no password and no other identity). Identity changes lock the account's row.
  • Back-channel logout: POST /api/v1/auth/everid/backchannel-logout (form-encoded logout_token). Access tokens of an Ever ID sign-in carry sid (the issuer's session, as an issuer-scoped key) and jti; once the issuer ends that session they answer 401, also when the logout arrives before the session's first sign-in here. Logout tokens older than 300 s, without the logout event, or replayed (ever_id_logout_jti) are refused. Tokens without sid (password, API client, Google) never reach the check. TR_AUTH_EVERID_BACKCHANNEL_LOGOUT_ENABLED=false turns the route off.
  • One migration (1794009600000-ever-id) creates user_identity, ever_id_session, ever_id_logout_jti on PostgreSQL, MySQL and SQLite (IF NOT EXISTS, camelCase columns on MySQL); down() drops only these three tables. No existing table changes.
  • New error answers keep their status and a stable code ({ error: { code, message, details? } }, Cache-Control: no-store) through one additive branch of the exception filter. The auth rate limit (TR_AUTH_THROTTLE_*) applies to the new routes (except back-channel logout, which the issuer sends from its own servers) and to Ever ID requests on signup-provider; Google requests on that route are not rate limited, as before.
  • No Ever ID token is stored or logged; the client secret never leaves the API.

Webapp

  • everid authorization request with state, nonce and PKCE S256, kept in session storage and read once by the callback; prompt=login&max_age=300 for a connect. No login_hint, no Google-specific parameters. The Google request string is unchanged.
  • The callback reads state (absent: Google, as before).
  • "Continue with Ever ID" text button on the sign-in and sign-up pages.
  • /auth/everid/confirm: "Create your Traduora account", name and email read-only, each pending invitation with its own unchecked checkbox.
  • Account Settings: "Connected sign-in methods" (shown only while Ever ID is on): connect with both emails shown before confirming, disconnect.
  • karma-jasmine added to the webapp dev dependencies: src/karma.conf.js already required it, so ng test could not start. A ChromeHeadlessCI launcher is added for CI.

Tests

  • API unit: oidc-provider.service.spec.ts (activation and the Ever-host rule, code exchange, ID token rejections, key set cache, cooldown and retry delay, logout tokens, documented claim examples with optional hints), ever-id-session.service.spec.ts (real migrations on in-memory SQLite: links, unlink rule, sealed records, issuer-scoped sessions, logout before first sign-in, logout replay, sweep), ever-id-static.spec.ts (no unverified decode on the Ever ID path, no redirect, no login_hint, no token in logs).
  • API e2e test/ever-id.e2e-spec.ts against a mock OpenID Connect issuer in test/mock-oidc/: off (zero requests, nock.disableNetConnect), Ever issuer without the cloud install source, discovery failure, listing, sign-up confirmation, equal email, invitations with signups disabled, connected sign-in, PKCE/nonce/unverified email rejections, connect, identities, back-channel logout, migration down and up, Google request body.
  • Webapp unit: authorization request (Ever ID and Google), callback, sign-in button, confirmation screen, settings card, NGXS state.
  • New ci workflow: API lint and unit tests, the e2e suite on SQLite, PostgreSQL and MySQL, webapp unit tests.

Local runs (Windows, Node 24):

SuiteSQLitePostgreSQL 18MySQL
API e2e, whole suite (18 files, auth.e2e-spec.ts unchanged)166 / 166166 / 166not run locally (no MySQL available)
API e2e, ever-id.e2e-spec.ts15 / 1515 / 15
API unit, new specs (OIDC provider, session service, static checks)48 / 48n/an/a
Webapp unit (ng test, headless Chrome)26 / 26

The new ci workflow (Linux, Node 26.12.1) on 610b519: API e2e 166 / 166 on SQLite, PostgreSQL 15 and MySQL 5.7; API lint and unit 95 / 95; webapp unit 26 / 26. CircleCI test green.

Also: tslint (API) clean, prettier --check clean on every changed file, tsc and ng build pass, yarn install --frozen-lockfile passes. The full API unit run is 88 / 89 on Windows: properties.spec.ts (untouched formatter) compares against os.EOL, so it fails on Windows only.

Configuration

See the new rows and the "Sign in with Ever ID (optional)" section of docs/configuration.md; docker-compose.yaml gains commented TR_AUTH_EVERID_* lines only (defaults unchanged).

🤖 Generated with Claude Code