Skip to content

[POC] Add 2FA interface#1

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

[POC] Add 2FA interface#1
santiagorodriguez96 wants to merge 10 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 test_otp 2FA method that simulates a real extension gem with a
simple OTP check. Add UserWithTwoFactor model (ActiveRecord + Mongoid),
shared behavior, migration, routes, and challenge view.
Add model tests for TwoFactorAuthenticatable (enabled/disabled states,
multiple methods, unknown method errors, model concern inclusion).
Add strategy tests for the base TwoFactor strategy. Add registration
tests for register_two_factor_method in devise_test.
Add end-to-end integration tests covering the full 2FA sign-in flow,
failure recall, password reset enforcement, route verification, and
URL helpers. Update serializable_test for new otp_secret column.
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.

2 participants