Scaffold comes with two factor authentication, recovery codes, spam protection, secure headers and device management built in.
Users can choose between two platforms on their security settings page (user/security/two-factor):
TwoFactorNotification).pragmarx/google2fa-laravel and bacon/bacon-qr-code).Choosing the authenticator shows the QR code and manual key, and the user confirms with a code from the app before it takes effect. Changing platforms is handled by the ProcessUserTwoFactorSettings action, which resets the old codes and logs an activity.
GET user/security/two-factor // setup PUT user/security/two-factor // choose a platform POST user/security/two-factor/confirm // confirm the authenticator
The two-factor middleware (App\Http\Middleware\TwoFactor) protects the authenticated app routes alongside verified. If the user hasn't confirmed their code for this login it sends the email code, or checks the authenticator, and redirects to verify/two-factor.
Route::middleware(['verified', 'two-factor'])->group(function () { // ... });
The two factor state lives in the HasTwoFactor concern on User.
Recovery codes are generated with pragmarx/recovery and emailed to the user (TwoFactorRecoveryNotification). A user who loses access can enter their email and a recovery code at /recovery, which turns off two factor so they can log in and set it up again.
Honeypot
The auth routes (login, register, password reset etc.) and the recovery routes are wrapped in spatie/laravel-honeypot's ProtectAgainstSpam middleware, and the auth routes are throttled to 5 attempts a minute. Settings are in config/honeypot.php.
hCaptcha
The hCaptcha middleware verifies an h-captcha-response with hCaptcha whenever a request includes one, using services.hcaptcha.secret. Add it to any route whose form renders an hCaptcha widget.
Disposable emails
Registration rejects disposable email addresses with erag/laravel-disposable-email's DisposableEmailRule.
Registration
Public registration is controlled by REGISTRATION (general.registration_available). With it off, people can still register through an invite.
bepsvpt/secure-headers is appended as global middleware and sets the security headers, including the content security policy. HSTS and the CSP are enabled. Settings are in config/secure-headers.php. A @nonce Blade directive is registered in AppServiceProvider as a placeholder (it outputs nothing) for when you add CSP nonces to inline scripts.
Each login records the device (browser, IP address and last login) through the HasDevices concern, using hisorange/browser-detect to describe it. Users can see their devices on their security page and log out of every other device, which requires their password.
POST user/logout // log out other devices
Admin routes also require a recently confirmed password (password.confirm).
yorcreative/laravel-scrubber scrubs sensitive values out of logs. Add your own patterns with:
php artisan make:regex-class
Routes for social logins with laravel/socialite are in place:
GET auth/{provider}/redirect
GET auth/{provider}/callback
SocialiteController is a starting point. Configure your provider in config/services.php and complete the callback to find or create the user and log them in.