Skip to content

feat(auth): add secure Google and GitHub sign-in with explicit account linking #288

Description

@parthrohit22

Summary

Add Google and GitHub as supported sign-in methods across the backend and frontend. The current product supports email/password only; the Iteration 1 design includes social sign-in controls, but they were intentionally omitted because no real backend contract exists.

This issue is separate from #220: #220 connects private GitHub repositories through a read-only GitHub App. This issue authenticates a PARTHA user. Authentication credentials, OAuth applications, scopes, and stored records must not be shared between the two concerns.

Current behavior

  • Backend auth exposes /auth/register, /auth/login, /auth/refresh, /auth/logout, and /auth/me.
  • A user has an email and an optional password hash; there is no external-identity model.
  • Login and registration pages expose only real email/password controls.
  • Adding decorative Google/GitHub buttons without this contract would create fake functionality.

Proposed scope

Backend

  • Add a provider-identity model keyed by (provider, provider_subject), linked to one PARTHA user through a new Alembic migration.
  • Implement Authorization Code flow with PKCE where supported, cryptographically random state, OIDC nonce for Google, strict redirect-URI allowlisting, and short-lived flow state.
  • Support Google and GitHub initiation/callback endpoints that finish in the existing PARTHA access-token plus HttpOnly refresh-cookie session.
  • Require verified provider identity data. Do not silently merge accounts by email.
  • For an email that already belongs to a PARTHA account, require explicit authenticated linking or password confirmation before linking.
  • Allow a signed-in user to link and unlink providers, while preventing removal of the final usable credential.
  • Never store provider access tokens unless an explicitly documented feature requires them. If temporary tokens are required during callback handling, do not log or return them.
  • Keep the seed/system user ineligible for interactive authentication.

Frontend

  • Add working “Continue with Google” and “Continue with GitHub” controls to login and registration.
  • Render a provider control only when the backend reports that provider as configured; otherwise omit it or show an honest unavailable state.
  • Handle cancellation, denied consent, state mismatch, duplicate identity, and link-required outcomes in plain language.
  • Add linked-account management under Settings → General.
  • Preserve the current email/password flow and auth guard.

Acceptance criteria

  • Google sign-in creates or authenticates the correct PARTHA user and starts the existing secure session.
  • GitHub sign-in creates or authenticates the correct PARTHA user and starts the existing secure session.
  • OAuth/OIDC state, PKCE, nonce, redirect allowlisting, and replay/expiry failure paths are covered by backend tests.
  • A matching email never causes silent account linking or account takeover.
  • Authenticated linking/unlinking is explicit, audited, owner-scoped, and cannot remove the final credential.
  • Provider tokens, authorization codes, client secrets, and PARTHA tokens never appear in URLs after callback completion, application logs, or API responses.
  • The frontend shows only configured providers and covers success, cancellation, provider error, and link-required states.
  • Email/password login, refresh rotation/reuse detection, logout, and guarded routes continue to pass.
  • OpenAPI, backend tests, frontend tests, accessibility checks, lint, production build, and Compose auth smoke checks pass.

Security and data considerations

Treat this as an authentication-boundary change. Threat-model login CSRF, account linking, email trust, replay, redirect manipulation, token leakage, provider outage, and credential removal. Any new dependency requires maintainer approval.

Non-goals

Roadmap alignment

Advances roadmap §23 W6 (Identity & Access: OIDC and secure credentials) toward §28 deployment-specific security gates, while reducing onboarding friction for the real-engineer testing workflow. Merge evidence must include the threat model, negative auth tests, and completed end-to-end sign-in journeys.

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions