hryvinskyi / magento2-customer-sign-in-passkey
Passkey sign-in for the customer sign-in suite: customers add passkeys from their account, sign in with one without typing an address, and use one to finish a sign-in that needs a second step.
Package info
github.com/hryvinskyi/magento2-customer-sign-in-passkey
Type:magento2-module
pkg:composer/hryvinskyi/magento2-customer-sign-in-passkey
Requires
- php: ~8.1.0||~8.2.0||~8.3.0||~8.4.0||~8.5.0
- hryvinskyi/magento2-clock: ^1.0
- hryvinskyi/magento2-customer-sign-in: ^1.0
- hryvinskyi/magento2-customer-sign-in-api: ^1.0
- hryvinskyi/magento2-customer-sign-in-frontend: ^1.0
- hryvinskyi/magento2-rate-limit: ^1.1
- hryvinskyi/magento2-webauthn: ^1.0
- magento/framework: *
- magento/module-config: *
- magento/module-customer: *
- magento/module-store: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A sign-in method of the customer sign-in suite. A customer adds passkeys from Sign-in & Security in My Account, then signs in with one by fingerprint, face or screen lock, without typing an email address or a password. A passkey also finishes a sign-in that waits for its second step. Passkeys are WebAuthn credentials that the device keeps and that always ask the person to unlock the device.
What the customer sees
Add a passkey
My Account > Sign-in & Security shows a Passkeys section: With a passkey you sign in with your fingerprint, face or screen lock instead of a password., then the customer's passkeys or You have no passkeys yet.
- The table Your passkeys lists each passkey with Name, Added, Last used (or Never) and a Remove button.
- Below it, the field Name of the new passkey (for example
Work laptop, up to 64 characters) and the button Add a passkey. The browser asks the customer to create the passkey and unlock the device. The page then showsThe passkey was added.A passkey added without a name is listed as Passkey. - A browser that cannot create passkeys shows
This browser cannot create passkeys. Open this page in a browser that supports them to add one.in place of the field and the button.
Adding or removing a passkey needs a recent sign-in, and the customer gets an email about each passkey added or removed (both from hryvinskyi/magento2-customer-sign-in-frontend and the sign-in engine). A passkey is also a second step: the customer's first passkey gives them ten recovery codes, shown once on Sign-in & Security after the add, and from then on a sign-in with the password or an email code goes on to Finish signing in, where the passkey or a recovery code finishes it. The codes go with the customer's last second-step method. 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.
Sign in with a passkey
Inside the sign-in form, under Sign In and Forgot Your Password? and the word or: the button Sign in with a passkey, beside the other ways to sign in (side by side on wide screens, stacked on narrow ones). A press that does not sign in shows why below the buttons. On browsers that support it, the passkeys also appear in the autofill list of the email field, on stores that switch autocomplete off too. The customer picks a passkey, unlocks the device, and is signed in.
A passkey sign-in is complete on its own: a customer whose account has a second step (an authenticator app, a phone or a passkey) is not asked for it. A browser without passkeys shows no button, and a browser without JavaScript shows none of the other ways to sign in.
Finish signing in with a passkey
On Finish signing in, a customer who has a passkey sees a Passkey part: Confirm with the passkey on this device or your phone. and the button Use a passkey. On a browser with passkeys the page asks for the passkey as soon as it opens, and the answer finishes the sign-in. Use a passkey asks again after the customer closed the browser's prompt.
Messages
| Message | Cause |
|---|---|
The passkey could not be used. Try again or sign in another way. |
The browser could not use the passkey, for a reason the store's answer does not name. |
This browser cannot use passkeys. |
The browser has no passkey support. |
The passkey could not be verified. |
What the device sent could not be verified. |
This passkey is not registered with this store. |
No passkey of this store has the id the device sent: it was removed, or added on another website. |
This passkey is already registered. |
The passkey the device created is one this store already has. |
The passkey request has expired. Try again. |
The passkey request was already used or has expired. |
This page has expired. Reload it and try again. |
The request did not carry the form key of the visitor's session. |
Too many passkey sign-ins were started from your network. Try again later. |
The network reached Passkey Sign-ins per Network per Hour. |
Passkey sign-in is not available. |
Passkeys are switched off for the website. |
You have no passkey for this store. Finish signing in another way. |
Use a passkey for a waiting customer who has no passkey for this store. |
Your sign-in has ended. Sign in again. |
Use a passkey after the waiting sign-in has ended. |
The name of a passkey can be at most 64 characters long. |
The name typed was longer. |
Configuration
Stores > Settings > Configuration > Customers > Sign-in Methods > Passkeys. The section needs the role resource Stores > Settings > Configuration > Customer Sign-in Methods.
| Setting | Path | Scope | Default | Effect |
|---|---|---|---|---|
| Enable Passkeys | customer_sign_in/passkey/enabled |
Website | 1 (Yes) |
Shows Sign in with a passkey, the autofill and the Passkeys section, and lets customers add passkeys and sign in with them. |
| Passkey Sign-ins per Network per Hour | customer_sign_in/passkey/options_per_client_hour |
Website | 300 |
How many passkey sign-ins one network address may start in any hour. 0 means no limit. Shown while Enable Passkeys is Yes. |
Every view of the sign-in page on a browser with passkey autofill starts a passkey sign-in, and an office or a mobile network shares one address among many visitors. Keep the limit high.
When it is switched off
On that website the sign-in page shows no passkey button and no autofill, Sign-in & Security shows no Passkeys section, and a passkey sign-in is refused with Passkey sign-in is not available. A customer who has a passkey can still use it on Finish signing in.
Security behaviour
- The device asks for the person. Every passkey is created and used with user verification required: fingerprint, face, PIN or screen lock.
- Discoverable passkeys. The passkey names its owner, so the sign-in needs no address.
- One store domain. A passkey works on the host of the store view's secure base URL (Stores > Settings > Configuration > General > Web > Base URLs (Secure)). Passkeys added there stop working if that host changes.
- One website. A passkey is kept for the website it was added on.
- Removed passkeys. A removed passkey no longer signs anybody in.
- Cloned passkeys. A passkey whose signature counter does not grow is refused. A device that always reports zero, as synced passkeys do, is accepted.
- The sign-in page stays in the full-page cache. The button prints no form key; it posts the visitor's own form key when it is pressed.
Limits
- The button needs JavaScript. The sign-in page shows its other ways to sign in once its script has run.
- Hyvä themes are not supported. The button, the section and the second-step part are Luma templates with RequireJS widgets.
Requirements
- Magento Open Source or Adobe Commerce 2.4.x with a Luma-based theme, served over HTTPS. The suite is built and tested on 2.4.9.
- PHP 8.1 to 8.5.
hryvinskyi/magento2-customer-sign-in-api,-customer-sign-inand-customer-sign-in-frontend^1.0,hryvinskyi/magento2-webauthn^1.0,hryvinskyi/magento2-rate-limit^1.1 andhryvinskyi/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-passkey bin/magento module:enable Hryvinskyi_Clock Hryvinskyi_RateLimit Hryvinskyi_VerificationCode Hryvinskyi_WebAuthn Hryvinskyi_CustomerSignInApi Hryvinskyi_CustomerSignIn Hryvinskyi_CustomerSignInFrontend Hryvinskyi_CustomerSignInPasskey 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, in a browser with passkeys: sign in as a customer, open Sign-in & Security and click Add a passkey. Sign out. The sign-in page shows Sign in with a passkey, and the passkey signs the customer in.
Registrations
| Where | What |
|---|---|
| Method pool | Item passkey in the methods argument of Hryvinskyi\CustomerSignIn\Model\MethodPool, global etc/di.xml: Model\PasskeyMethod, roles SignIn, Verification and Enforcement. |
| Storefront route | Added to frontName customersignin before Hryvinskyi_CustomerSignInFrontend, all POST with JSON answers and the form key checked: passkey/signInOptions, passkey/signIn, passkey/registerOptions, passkey/register, passkey/verifyOptions, passkey/verify. |
| Layout | customer_account_login: customer.signin.passkey.button in customer.signin.login.alternatives (the sign-in form's other ways to sign in, from hryvinskyi/magento2-customer-sign-in-frontend), last. customersignin_security_index: customer.signin.security.passkey in customer.signin.security.sections. customersignin_verify_index: customer.signin.verify.passkey in customer.signin.verify.methods. |
| Scripts | js/passkey-sign-in, js/passkey-register, js/passkey-verify, with passkey-widget, passkey-ceremony, passkey-endpoints, passkey-page, widget-config and autocomplete-tokens. |
| Tables | hryvinskyi_customer_sign_in_passkey (one row per passkey factor: website, credential id and its SHA-256, public key, signature counter, authenticator model, transports; deleted with its factor) and hryvinskyi_customer_sign_in_passkey_user (the random user handle of each customer; deleted with the customer). |
| Rate-limit bucket | customer_sign_in_passkey_client: passkey sign-ins started per client address, sliding hour. |
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="passkey" xsi:type="object">Hryvinskyi\CustomerSignInPasskey\Model\PasskeyMethod</item> </argument> </arguments> </type>
PasskeyMethod implements Hryvinskyi\CustomerSignInApi\Api\SignInMethodInterface: code passkey, label Passkey, roles [SignInRole::SignIn, SignInRole::Verification, SignInRole::Enforcement], switched on per website by customer_sign_in/passkey/enabled. With the Enforcement role a customer's passkey makes the second step due after any other first step. Its sign-in button, account section and second-step part use the containers and view models of hryvinskyi/magento2-customer-sign-in-frontend, and the WebAuthn ceremonies come from hryvinskyi/magento2-webauthn.
Tests
Run from the Magento root.
- Unit:
vendor/bin/phpunit -c app/code/Hryvinskyi/CustomerSignInPasskey/phpunit.xml.dist. - Browser scripts (Node's own test runner):
node --test app/code/Hryvinskyi/CustomerSignInPasskey/Test/Js/*.test.mjs. - 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/CustomerSignInPasskey/Test/Integration. - Static analysis: PHPStan 2.x at level 10 with the package's
phpstan.neon.dist(phpstan analyse -c app/code/Hryvinskyi/CustomerSignInPasskey/phpstan.neon.dist --level=10) andvendor/bin/phpcs --standard=app/code/Hryvinskyi/CustomerSignInPasskey/phpcs.xml.dist app/code/Hryvinskyi/CustomerSignInPasskey.
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.