githubEdit

User Registration

The Symfony UX WebAuthn package provides Stimulus controllers to simplify the registration of new authenticators. This page explains how to register a new user with WebAuthn or add authenticators to an existing user account.

New User Registration

When registering a new user, you need to collect basic information (username, display name) and then register their first authenticator.

Registration Form

Your registration form needs:

  1. A username field for the user's identifier

  2. A display name field (optional, can default to username)

  3. A hidden field for the attestation response

templates/registration/register.html.twig
<form
    action="{{ path('app_register') }}"
    method="post"
    {{ stimulus_controller('@web-auth/webauthn-stimulus',
        {
            creationOptionsUrl: path('webauthn.controller.creation.creation.new_user'),
            creationResultField: 'input[name="attestation"]'
        }
    ) }}
>
    <label for="username">Username</label>
    <input
        type="text"
        id="username"
        name="username"
        required
        autocomplete="username webauthn"
    >

    <label for="displayName">Display Name</label>
    <input
        type="text"
        id="displayName"
        name="displayName"
        placeholder="John Doe"
    >

    <input type="hidden" id="attestation" name="attestation">

    <button
        type="submit"
        {{ stimulus_action('@web-auth/webauthn-stimulus', 'register') }}
    >
        Register with Passkey
    </button>
</form>

Bundle Configuration

Configure the bundle to handle new user registration:

User Entity Guesser

Create a guesser to handle new user registration:

circle-info

After successful registration, save both the user entity and the credential source to your database. The controller automatically validates the attestation response.

Adding Authenticators to Existing Users

Existing users can register additional authenticators (backup keys, different devices).

Add Authenticator Form

Configuration for Existing Users

circle-check

Stimulus Controller Options

The registration controller accepts the following options:

Option
Type
Required
Description

creationOptionsUrl

string

Yes

URL to fetch credential creation options

creationResultField

string

Yes

CSS selector for the hidden attestation field

autoRegister

boolean

No

Automatically trigger registration on page load (default: false)

Auto-Register Example

Automatically start the registration process when the page loads:

circle-exclamation

Dedicated Registration Controller

circle-info

New in v5.3.0: A dedicated registration controller is available alongside the combined controller.

The dedicated registration-controller provides a focused controller for credential registration with enhanced features like conditional create support.

Basic Usage

Registration Controller Options

Option
Type
Default
Description

optionsUrl

string

/registration/options

URL to fetch creation options

resultUrl

string

/registration/verify

URL to submit the attestation response

submitViaForm

boolean

false

Submit via form instead of fetch

successRedirectUri

string

-

URL to redirect after successful registration

autoRegister

boolean

false

Auto-start registration on page load

Registration Controller Targets

Target
Description

username

Input field for the username

attestation

Select field for attestation preference

residentKey

Select field for resident key preference

userVerification

Select field for user verification preference

authenticatorAttachment

Select field for authenticator attachment preference

result

Hidden input for the attestation response

Error Handling

Handle registration errors in your custom event listeners:

See Also

Last updated

Was this helpful?