Repository navigation
✨ Add a ForceTwoFactor facade to bypass the 2FA enforcement - #1
Merged
Merged
Conversation
Register a callback (e.g. for SSO admins whose second factor is handled by the identity provider) that exempts a request from the forced 2FA enrolment. Backed by a container-singleton manager so callbacks survive config:cache and stay test-isolated; the middleware consults it before redirecting an un-enrolled admin to the User Security page. The workbench demoes it: an `is_sso` column, a seeded SSO admin, and a ForceTwoFactor::bypass() callback in NovaServiceProvider — under `composer serve`, sso@example.com reaches Nova without enrolling while no2fa-valid@example.com is still forced to. Also commit composer.lock (and stop ignoring it) for reproducible CI, matching laravel-password-rotation and nova-password-rotation.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Add feature coverage for multiple callback composition and short-circuit evaluation.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
What changed in this PR
Adds a ForceTwoFactor facade and singleton manager for runtime 2FA bypass callbacks, including an SSO workbench demonstration.
Changes:
- Adds callback registration and middleware integration.
- Adds SSO demo data, migration, and provider configuration.
- Tracks
composer.lockand updates.gitignore.
Review note: Add coverage for multiple callbacks, including false-then-true evaluation and short-circuiting.
| File | Description |
|---|---|
workbench/database/seeders/DatabaseSeeder.php |
Seeds an SSO admin. |
workbench/database/migrations/2024_01_01_000002_add_is_sso_to_users_table.php |
Adds the SSO database field. |
workbench/app/Providers/NovaServiceProvider.php |
Registers the SSO bypass callback. |
workbench/app/Models/User.php |
Adds SSO model support. |
tests/Feature/MiddlewareTest.php |
Tests bypass behavior and callback arguments. |
src/TwoFactorManager.php |
Stores and evaluates bypass callbacks. |
src/NovaForceTwoFactorServiceProvider.php |
Registers the manager singleton. |
src/Http/Middleware/EnsureTwoFactorEnabled.php |
Applies bypass callbacks. |
src/Facades/ForceTwoFactor.php |
Exposes the bypass API. |
.gitignore |
Allows composer.lock to be tracked. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+47
to
+49
| foreach ($this->bypassCallbacks as $callback) { | ||
| if ($callback($request, $user)) { | ||
| return true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Adds a runtime bypass hook so specific requests can be exempted from the forced two-factor enrolment — the motivating case being SSO admins whose second factor is handled by the identity provider and who shouldn't be pushed into local (Fortify) 2FA. Mirrors the
PasswordRotation::bypass()hook inlaravel-password-rotation.API
EnsureTwoFactorEnabled::shouldPassThrough()consults the callback only for an authenticated, not-yet-enrolled admin; returningtruelets the request through. Several callbacks may be registered — anytrueexempts the request.Design
TwoFactorManager, bound as a container singleton inpackageRegistered()(before the auto-registration guard), so the facade and the middleware share one instance and callbacks surviveconfig:cache.ForceTwoFactorfacade. No dependency on the password-rotation core (distinct 2FA semantics).Also
composer.lock(and stop ignoring it) for reproducible CI — matching the base and nova twin.Workbench demo
An
is_ssocolumn, a seeded SSO admin, and aForceTwoFactor::bypass()callback inNovaServiceProvider. Undercomposer serve,sso@example.comreaches Nova without enrolling whileno2fa-valid@example.comis still forced to.Verification
composer buildseeds cleanly.