Skip to content

Add a standardized two-factor authentication interface for connecting devise extensions that implement 2FA methods #5842

Open

Description

@santiagorodriguez96

Every gem that adds 2FA support to Devise (devise-webauthn, devise-otp, devise-two-factor, etc.) independently solves the same set of problems:

  • Redirecting to a 2FA challenge page after password validation succeeds
  • Preserving remember_me across the two-step flow
  • Preventing 2FA bypass through password reset (PasswordsController#update calls sign_in directly)

Because each gem solves these independently – and with fundamentally different architectural choices (e.g. devise-two-factor replaces DatabaseAuthenticatable with a strategy that validates password and the OTP code, while devise-webauthn runs a separate Warden strategy) – there is no shared contract between them. An application that wants to offer users a choice between two second factors (e.g. WebAuthn and TOTP) cannot simply install two 2FA gems and have them cooperate out of the box.

I believe the Devise ecosystem would benefit from a standardized interface that extension gems can hook into instead of reimplementing the same patterns independently.

Activity

  1. carlosantoniodasilva commented on May 15, 2026

    @carlosantoniodasilva
    Member

    @santiagorodriguez96 thanks for writing this up and opening the PR.

    Just wanted to leave you a quick note that I've seen the change, just haven't had time to fully dig into it... it's quite a lot :)

    To be honest, I've always thought Devise should provide some minimal 2FA (with OTP probably) implementation, and at a glance I feel a bit uneasy supporting a whole lot of infrastructure without a concrete implementation... anyway, I'll be taking a better look and reporting back. Thanks again!

  2. santiagorodriguez96 commented on May 25, 2026

    @santiagorodriguez96
    Author

    Hey @carlosantoniodasilva!

    No worries at all – I know the PR is pretty big, please take your time. I really appreciate the effort that goes into maintaining OSS gems. And as mentioned in the PR, I'm happy to split this into smaller PRs if that would make review easier.

    I actually share your concern about adding infrastructure without a concrete implementation. That's exactly why I tried to ground the proposal by applying the infrastructure changes to a few existing Devise extensions and bringing them together into a demo app – see the "Validating the interface" section of the PR description for details. In fact, I also considered adding recovery codes as a 2FA strategy within the same PR, but decided to leave that for a follow-up to keep the scope manageable. If it helps move things forward, I'd also be glad to contribute to a built-in OTP implementation on top of this interface.

    Thanks again!

  3. santiagorodriguez96 commented on May 25, 2026

    @santiagorodriguez96
    Author

    Sorry, misclicked 🥴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions