Skip to content

[POC] Add 2FA interface#1

Open
santiagorodriguez96 wants to merge 6 commits intomainfrom
sr--2fa-interface
Open

[POC] Add 2FA interface#1
santiagorodriguez96 wants to merge 6 commits intomainfrom
sr--2fa-interface

Conversation

@santiagorodriguez96
Copy link
Copy Markdown
Collaborator

No description provided.

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.
Sign up for free to 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