Open
Conversation
Add Devise.register_two_factor_method API for extensions to register 2FA methods (analogous to config.omniauth). Register a single :two_factor_authenticatable module in modules.rb. Extend mapping strategies to include 2FA methods for Warden scope defaults. Provide TwoFactorAuthenticatable base model module with per-model two_factor_methods config, enabled_two_factors discovery, and automatic inclusion of extension model concerns.
Provide a base strategy that handles shared 2FA boilerplate: finding the pending resource from session, calling verify_two_factor!, restoring remember_me, and cleaning up session state on success. Extensions subclass and implement valid? + verify_two_factor!. The base strategy returns valid? false to prevent accidental use.
Add TwoFactorController following the OmniAuth callbacks pattern: a single controller with per-method new_<method> actions, a central POST create endpoint, and an ActiveSupport.on_load hook for extensions. Generate per-method challenge routes from mapping.to.two_factor_methods. Add generic URL helpers (new_two_factor_challenge_path, two_factor_path) included via engine initializer when 2FA methods are registered.
Modify DatabaseAuthenticatable strategy to detect 2FA-enabled users after password validation and redirect to the default 2FA method's challenge page instead of signing in. Update PasswordsController to require 2FA verification after password reset when sign_in_after_reset_password is enabled.
Add two_factor_method_links helper to DeviseHelper for rendering switch links between 2FA methods. Add locale strings for session expired, sign-in not initiated, and password reset 2FA required.
Add test_otp 2FA method for integration testing with a simple OTP check. Add model tests for TwoFactorAuthenticatable, strategy tests for the base TwoFactor strategy, and end-to-end integration tests covering the full sign-in flow, failure recall, and URL helpers.
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.
No description provided.