Skip to content

feat(auth): GitHub and Google social login with admin controls - #165

Merged
LeoStehlik merged 2 commits into
masterfrom
feat/social-login
Nov 23, 2026
Merged

LeoStehlik merged 2 commits into
masterfrom
feat/social-login

Conversation

@LeoStehlik

@LeoStehlik LeoStehlik commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Behavior

Adds GitHub OAuth and Google OIDC login alongside password login and Entra SAML. Administrators configure and enable each provider independently in workspace Security settings; both start disabled and signup defaults off. Members can explicitly connect identities in account settings. Existing accounts are never silently linked by matching email.

  • Authorization-code flows use S256 PKCE for both providers, Google nonce/token validation, and ten-minute single-use Redis state bound to a separate HttpOnly browser cookie per attempt. Linking additionally requires the same valid login session that initiated it, with recent authentication checked at initiation.
  • Stable GitHub IDs / Google subjects identify users within a workspace. New signup trusts the provider-verified email without sending another verification email, while respecting signup, domain and cloud-invitation rules. A provider email cannot verify a different local address.
  • Social login shares password authentication's MFA/session finalizer. Required MFA challenges do not create a successful-login audit record or update last-login time before completion. Signed challenges retain provider attribution. The browser handles the fragment token before redirecting and supports refreshing the challenge page.
  • Enforced SAML blocks social login and linking at initiation and callback, including enforcement enabled mid-flow. Disabling a provider rejects pending callbacks. Social providers cannot satisfy the enterprise-enforcement prerequisite.
  • Disconnect/reconnect reuses only the authenticated user's disconnected association. Active links cannot be overwritten or reassigned; database constraints reject concurrent competing identity claims.
  • Secrets are encrypted with AppSecretCryptoService; provider responses expose configured status and callback URL, never the stored secret. Configuration and identity changes are audited with workspace/provider attribution.

Migration and setup

20261123T120000-social-auth-providers.ts adds partial unique indexes for one configuration per workspace/provider and one active owner per provider identity. The review fixes require no additional migration or database reset. Existing content and volumes must be preserved.

Setup and test instructions cover both OAuth registrations. Register the exact callback shown in the UI:

  • https://<host>/api/auth/social/github/callback
  • https://<host>/api/auth/social/google/callback

For a shared live test, use an HTTPS hostname accepted by both providers and matching the configured application URL. Google does not accept an arbitrary private HTTP hostname; localhost has separate development exceptions.

Verification

  • pnpm --filter server exec jest --runInBand: 298 passed, 13 opt-in database tests skipped in this invocation. Includes existing password/SAML regressions, real Nest/Fastify HTTP cookie and JWT-guard tests, and Google token validation through the actual OIDC library against local token/JWKS endpoints with signed synthetic tokens.
  • WRENLORE_SOCIAL_TEST=disposable SOCIAL_INTEGRATION_DB=... SOCIAL_INTEGRATION_REDIS=... node scripts/social-ci.cjs: 13 passed against isolated PostgreSQL 18 + Redis, including reconnects, active-link protection and concurrent identity claims. Provider endpoints are mocked.
  • node scripts/social-ui.cjs: Chromium passes fresh-browser MFA, refresh/submission/cleanup, stale/missing-token handling and SAML account-link controls. Uses real components with mocked application API responses.
  • pnpm --filter server build and pnpm --filter client build: pass.
  • node scripts/history-ui.cjs and node scripts/history-ui.cjs --full-editor: pass locally in Chromium and WebKit, including desktop/short/mobile history controls and full-editor rendering.
  • Full compiled application boot and /api/health: pass against disposable PostgreSQL/Redis.
  • Added a social-authentication CI workflow to retain these regressions.

Live provider verification remains outstanding: no real GitHub/Google account authorization has been performed. It requires registered OAuth client IDs/secrets and the chosen callback hostname. Mock endpoints and signed synthetic tokens establish protocol handling, not a completed live-provider rollout.

Leave merge, deployment and release pending joint review. Production has not been changed.

Adds server-side authorization-code social login for GitHub (OAuth) and
Google (OIDC) alongside the existing Entra SAML SSO and password login.

Server:
- New core/sso/social module: provider drivers (GitHub OAuth, Google OIDC
  via openid-client with id_token signature/issuer/audience/expiry/nonce
  validation), single-use browser-bound state in Redis (GETDEL, 10 min
  TTL, workspace+provider+operation bound), PKCE S256 for Google.
- Identity resolution by stable provider ids (GitHub user id, Google sub);
  no silent email-match linking. Signup only with provider-verified email,
  allowSignup enabled, and workspace domain allowlist respected; cloud mode
  requires an invitation. Provider tokens are discarded after identity
  resolution.
- Login completes through the normal session path including MFA challenge
  (mfa token handed over via URL fragment) and MFA-setup enforcement, not
  the SAML direct-cookie shortcut.
- Account connect flow in account settings requires a recent sign-in
  (JWT iat within 10 minutes); link collisions and cross-workspace states
  are rejected; DB unique index backs concurrent-callback safety.
- Enforced SAML SSO blocks social login in start/callback/link paths and
  social providers no longer satisfy the "at least one active SSO provider"
  requirement for enabling enforcement.
- Provider admin reuses /sso endpoints: one GitHub and one Google config
  per workspace (DB-enforced), secrets encrypted with AppSecretCryptoService,
  only a hasClientSecret boolean and exact callback URL exposed; secrets
  never appear in API responses, logs, or audit payloads.
- Audit events for provider config changes, identity link/unlink,
  successful social logins (with actor), and safe login-failure records.

Client:
- "Continue with GitHub/Google" buttons on the login page, shown only for
  enabled providers and hidden when SSO is enforced; translated error
  notifications for callback failures.
- Security settings: per-provider cards (client id, write-only secret,
  enable, allow sign-ups, copyable callback URL).
- Account settings: connected accounts with connect/disconnect.
- MFA challenge accepts a token handed over via URL fragment.

Migration 20261123T120000 adds partial unique indexes (one social provider
per workspace type; one account per provider identity per workspace).

Tests: unit specs for the service, both drivers, and provider management;
opt-in integration spec runs the real controller flow against PostgreSQL
and Redis with mocked provider endpoints; full jest suite green.

Docs: docs/SOCIAL_LOGIN_SETUP.md.
Signed-off-by: Leo Stehlik <[email protected]>
@LeoStehlik
LeoStehlik merged commit af80647 into master Nov 23, 2026
4 of 5 checks passed
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.

1 participant