Skip to content
Customer Two-Factor Authentication: 2FA for customers on Mage-OS
Mage OS · 4 min read

Customer Two-Factor Authentication: 2FA for customers on Mage-OS

I have released a new open source module for Mage-OS: Customer Two-Factor Authentication, available on Mage-OS Lab.

Magento 2 already includes the Magento_TwoFactorAuth module, but it only protects the admin panel. There was no native solution for storefront customers. This module fills the gap by adding TOTP two-factor authentication (RFC 6238) to customer accounts, compatible with common authenticator apps.

How it works

2FA is optional and voluntary: each customer can turn it on or off from their own dashboard in My Account, where they can also regenerate their recovery codes.

Once active, the code is requested in the standard login, in Luma’s authentication popup and in OneStepCheckout.

Main features

  • QR code generated server-side as SVG: the secret is never sent to third-party services
  • Recovery codes stored as SHA-256 hashes, which can be copied or downloaded
  • Fail-closed architecture, to prevent access through alternative login paths
  • Replay protection, with configurable clock tolerance and maximum number of attempts
  • Secret stored in encrypted form
  • Password required to turn 2FA off
  • 2FA reset from the admin and via CLI command
  • Hyvä-compatible templates
  • en_US and it_IT translations

Installation

composer require mage-os/module-login-two-factor-auth
bin/magento module:enable MageOS_LoginTwoFactorAuth
bin/magento setup:upgrade
bin/magento config:set customer_2fa/general/enabled 1

Configuration

The options are in Stores → Configuration → Customers → Two-Factor Authentication:

  • enabled: turns the feature on (website scope)
  • issuer: label shown in the authenticator app
  • leeway: accepted time windows (0 to 2, default 1)
  • max_attempts: failed attempts before asking for the password again
  • recovery_codes: number of recovery codes generated (default 10)

Current limitations

The GraphQL generateCustomerToken and REST tokens are not yet subject to 2FA verification. Device recognition and email notifications are not implemented at the moment.

License and contributions

The module is released under the MIT license. The code is available on GitHub: mage-os-lab/module-customer-two-factor-auth.

Feedback, bug reports and contributions are welcome.

You might also like