Search by

hryvinskyi / magento2-customer-sign-in-totp

hryvinskyi

Authenticator app sign-in method for the customer sign-in suite: a customer turns it on by scanning a QR code with any authenticator app (RFC 6238) and confirming one code, and every later password or e-mail code sign-in then asks for a current code from the app.

Package info

github.com/hryvinskyi/magento2-customer-sign-in-totp

Type:magento2-module

pkg:composer/hryvinskyi/magento2-customer-sign-in-totp

Statistics

Installs: 1

Dependents: 1

Suggesters: 1

Stars: 0

Open Issues: 0

1.0.0 2026-12-03 08:34 UTC

This package is auto-updated.

Last update: 2026-12-03 14:17:43 UTC


README

A sign-in method of the customer sign-in suite. A customer turns on an authenticator app in Sign-in & Security. From then on, every sign-in with a password or an email code asks for the 6-digit code the app shows. Any app that reads the standard time-based code QR code works (RFC 6238). The app cannot sign a customer in alone: it is a second step only.

What the customer sees

Turn the app on

My Account > Sign-in & Security has an Authenticator app section. While the app is off it reads Off. With it on, you enter a code from an app on your phone each time you sign in. with the button Set up.

Set up opens the page Set up an authenticator app:

  1. Scan this QR code with the authenticator app on your phone. and the QR code.
  2. Cannot scan it? Enter this key in the app instead: and the key, in groups.
  3. Enter the 6-digit code the app shows., the field Code from your authenticator app, the button Turn on, and Back to Sign-in & Security.

After Turn on the customer returns to Sign-in & Security with Authenticator app is on. When this is the customer's first second step, the page shows their ten new recovery codes once, to save. The customer gets an email that a sign-in method was added.

Opening Set up and clicking Turn on need a recent sign-in (hryvinskyi/magento2-customer-sign-in-frontend).

Sign in with the app

After the password or the email code, the Finish signing in page shows an Authenticator app part with the field Code from your authenticator app and the button Verify. The current code finishes the sign-in. Each code works once. A customer without the phone uses a recovery code on the same page.

Turn the app off

While the app is on, the section reads On since <date> with the button Turn off. Turning it off needs a recent sign-in and sends the customer an email. When it was the customer's last second step, the recovery codes go with it, and the customer signs in with their password alone. While the store requires a second step from the customer's group, the customer cannot remove their last second step: the page shows Your store requires a second sign-in step. Add another method before you remove this one.

Messages

Message Cause
That code is not right. Check the time on your phone and try again. A wrong code on the setup page. The setup page stays, with the same QR code.
Setting up took too long. Scan the new QR code and enter the code it shows. More than 10 minutes passed since the setup page was first shown. The page shows a new QR code.
You already use an authenticator app. A second app for the same customer. A customer has one app at most.
The authenticator app is not available. Set up while the app is switched off for the website.
Enter the code from your authenticator app. Verify with an empty field on Finish signing in.

A wrong code on Finish signing in shows that page's own messages, listed in the README of hryvinskyi/magento2-customer-sign-in-frontend.

Configuration

Stores > Settings > Configuration > Customers > Sign-in Methods > Authenticator App. The section needs the role resource Stores > Settings > Configuration > Customer Sign-in Methods.

Setting Path Scope Default Effect
Enabled customer_sign_in/totp/enabled Website 1 (Yes) Shows the Authenticator app section on Sign-in & Security and lets customers turn the app on.
Name Shown in the App customer_sign_in/totp/issuer Store view empty The name the app shows above the store's codes. Empty uses Store Name from General > Store Information, or the store's domain when that is empty too.

When it is switched off

On that website Sign-in & Security shows no Authenticator app section, and Set up is refused. A customer who already uses the app is still asked for its code on Finish signing in, and it still works. They cannot see or turn off the app on Sign-in & Security while it is switched off: an admin removes it on the customer's Sign-in methods tab (hryvinskyi/magento2-customer-sign-in-admin-ui).

Security behaviour

  • Codes. Six digits. A code passes when the app shows it now or one time step before or after. A code that was accepted once, for turning the app on or for a sign-in, is refused after that.
  • Wrong codes. The attempts and the hourly limit of Finish signing in apply (Second Step Attempts, Wrong Second Step Entries per Hour under Sign-in Methods > General).
  • The key. The app's key is stored encrypted with the store's encryption key. A key that the store can no longer decrypt fails like a wrong code: if the encryption key changes without re-encrypting this table, customers who use the app finish with a recovery code, or an admin removes the app.
  • Setup. A setup lasts 10 minutes from the first view of the setup page, for the customer it was made for. Reloading the page shows the same QR code and does not extend it.

Limits

  • One app per customer is enforced in the application code, not by a database constraint. Two setups confirmed for one customer at the same moment could both pass.
  • The phone's clock must be right. An app whose clock is more than one time step off shows codes the store refuses.
  • Only the password sign-in and the email code ask for the app. A module that signs a customer in without the platform's password check opens the session with no second step. Customer tokens of the REST and GraphQL APIs are refused for a customer with the app on (see hryvinskyi/magento2-customer-sign-in).
  • Hyvä themes are not supported. The section, the setup page and the second-step part are Luma templates.

Requirements

  • Magento Open Source or Adobe Commerce 2.4.x with a Luma-based theme. The suite is built and tested on 2.4.9.
  • PHP 8.1 to 8.5.
  • hryvinskyi/magento2-customer-sign-in-api, -customer-sign-in and -customer-sign-in-frontend ^1.0, hryvinskyi/magento2-totp ^1.0 and hryvinskyi/magento2-clock ^1.0.
  • The platform's Config, Customer and Store modules.

Installation

Run from the Magento root. hryvinskyi/magento2-customer-sign-in-pack installs this package with the rest of the suite.

composer require hryvinskyi/magento2-customer-sign-in-totp
bin/magento module:enable Hryvinskyi_Clock Hryvinskyi_RateLimit Hryvinskyi_VerificationCode Hryvinskyi_Totp Hryvinskyi_CustomerSignInApi Hryvinskyi_CustomerSignIn Hryvinskyi_CustomerSignInFrontend Hryvinskyi_CustomerSignInTotp
bin/magento setup:upgrade
bin/magento setup:di:compile  # production mode only
bin/magento setup:static-content:deploy -f  # production mode only
bin/magento cache:flush

Verify on the storefront: sign in as a customer and open Sign-in & Security. The Authenticator app section shows Set up. Turn the app on, sign out, and sign in with the password: Finish signing in asks for the app's code.

Registrations

Where What
Method pool Item totp in the methods argument of Hryvinskyi\CustomerSignIn\Model\MethodPool, global etc/di.xml: Model\TotpMethod, roles Verification and Enforcement.
Storefront route Added to the route customersignin before Hryvinskyi_CustomerSignInFrontend: totp/setup (GET), totp/confirm (POST, code), totp/verify (POST, factor_id and code). Every POST carries the form key.
Layout customersignin_totp_setup (the setup page, cacheable="false"); customer.signin.security.totp in customer.signin.security.sections; customer.signin.verify.totp in customer.signin.verify.methods.
Table hryvinskyi_customer_sign_in_totp: the encrypted key and the last time step accepted of each app factor, deleted with its factor.

The package registers no cron job, command or ACL resource.

Extension points

The method joins the engine's pool from the global etc/di.xml, keyed by its code. An area di.xml that names this argument would replace the list, so a method is never registered there.

<type name="Hryvinskyi\CustomerSignIn\Model\MethodPool">
    <arguments>
        <argument name="methods" xsi:type="array">
            <item name="totp" xsi:type="object">Hryvinskyi\CustomerSignInTotp\Model\TotpMethod</item>
        </argument>
    </arguments>
</type>

TotpMethod implements Hryvinskyi\CustomerSignInApi\Api\SignInMethodInterface: code totp, label Authenticator app, roles [SignInRole::Verification, SignInRole::Enforcement], switched on per website by customer_sign_in/totp/enabled. The Enforcement role makes the second step due for every later sign-in of a customer who has the app, and the engine creates the recovery codes with the first such factor. The account section, the setup controller and the second-step part use the containers, view models and responders of hryvinskyi/magento2-customer-sign-in-frontend.

Tests

Run from the Magento root.

  • Unit: vendor/bin/phpunit -c app/code/Hryvinskyi/CustomerSignInTotp/phpunit.xml.dist.
  • Integration: the platform's harness in dev/tests/integration, against its own database, one run at a time. cd dev/tests/integration && php -d memory_limit=4G ../../../vendor/bin/phpunit -c phpunit.xml ../../../app/code/Hryvinskyi/CustomerSignInTotp/Test/Integration.
  • Static analysis: PHPStan 2.x at level 10 with the package's phpstan.neon.dist (phpstan analyse -c app/code/Hryvinskyi/CustomerSignInTotp/phpstan.neon.dist --level=10) and vendor/bin/phpcs --standard=app/code/Hryvinskyi/CustomerSignInTotp/phpcs.xml.dist app/code/Hryvinskyi/CustomerSignInTotp.

Translations

The storefront wording and the admin labels ship in en_US and 25 more locales: the official languages of the European Union, Norwegian Bokmål and Ukrainian. The translations are machine-made and no native speaker has read them. Have them checked before a store relies on them, and override a phrase in a theme or a language pack.