Skip to content

Add opt-in two-factor authentication via Laravel Fortify - #352

Open
sandervanhooft wants to merge 1 commit into
ploi:mainfrom
sandervanhooft:claude/2fa-login-features-240a84
Open

Add opt-in two-factor authentication via Laravel Fortify#352
sandervanhooft wants to merge 1 commit into
ploi:mainfrom
sandervanhooft:claude/2fa-login-features-240a84

Conversation

@sandervanhooft

Copy link
Copy Markdown

Summary

Adds opt-in two-factor authentication (TOTP) using Laravel Fortify, wired into the existing laravel/ui login flow. The public site and the Filament admin panel share the same web guard and session, so placing the 2FA challenge at /login protects both surfaces with a single enrollment and a single challenge — no separate admin-panel 2FA needed.

Fortify runs headless (Fortify::ignoreRoutes()); only the two-factor challenge and management flows are registered, so nothing conflicts with the existing Auth::routes() login / registration / password-reset controllers.

What's included

  • Login challenge — after a valid password, accounts with confirmed 2FA are redirected to /two-factor-challenge (authenticator code or recovery code) instead of being logged in. SSO / Socialite logins are unaffected (the IdP handles MFA there).
  • Self-service management in the profile page (Livewire / Filament): enable → scan QR → confirm, view and regenerate recovery codes, and disable. Enabling and disabling require the current password.
  • Tailwind challenge view and profile UI matching the app's existing styling.
  • Migration adding two_factor_secret, two_factor_recovery_codes, two_factor_confirmed_at.
  • TwoFactorAuthenticatable on the User model; the secret and recovery codes are hidden from serialization.

Testing

  • 15 new Pest tests covering the challenge flow (redirect, valid/invalid TOTP, recovery code, throttling, no-challenge-on-bad-password) and management (enable / confirm / disable / regenerate with password confirmation, plus rendered states).
  • Full suite green.

Notes

  • Run php artisan migrate to add the new columns.
  • 2FA is purely opt-in — no enforcement middleware is added.

Unified TOTP 2FA at /login that protects both the public site and the
Filament admin panel through the shared web session. Fortify runs headless
(routes ignored) alongside the existing laravel/ui login; only the 2FA
challenge and management flows are wired in.
- LoginController redirects password-verified users with confirmed 2FA to
the challenge instead of authenticating; SSO logins are unaffected
- Two-factor management (enable/confirm/disable/regenerate) added to the
Profile Livewire component with password confirmation
- Tailwind challenge view and profile UI (QR, setup key, recovery codes)
- Adds two_factor_secret/recovery_codes/confirmed_at columns
- 15 Pest tests covering the challenge flow and management
@sandervanhooft

Copy link
Copy Markdown
Author

not manually tested yet

Sign up for freeto 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

@sandervanhooft