Register Additional Authenticators
In some circumstances, you may need to register a new authenticator for a user e.g. when adding a new authenticator or when an administrator acts as another user to replace a lost device.
It is possible to perform this ceremony programmatically.
You can attach several authenticators to a user account. It is recommended in case of lost devices or if the user gets access on your application using multiple platforms (smartphone, laptop…).
The Easy Way
The procedure is the same as the one described in this page, except that you don’t have to save the user entity again.
The Hard Way
The procedure is the same as the one described in this page.
The Symfony Way
The following procedure is only available with the version 3.3.0+ of the bundle.
With a Symfony application, the fastest way for a user to register additional authenticators is to use the “controller” feature.
To add a new authenticator to a user, the bundle needs to know to whom it should be added. This can be:
The current user itself e.g. from its own account
An administrator acting for another user from a dashboard
For that purpose, a User Entity Guesser service should be created. This servuce shall implement the interface Webauthn\Bundle\Security\Guesser\UserEntityGuesser
and its unique method findUserEntity
. In the example herafter, the current user is used as User Entity.
In the case the current user is an administrator, the user entity can be determined using query parameters e.g. using routes like /admin/add-authenticator/for/{USER_ID}
.
The user is retrieved using the associated repository and the given ID.
Now you just have to enable the feature and set the routes to your options and response controllers.
As the user shall be authenticated to register a new authenticator, you should protect these routes in the security.yaml
file.
Now you can send requests to these new endpoints. For example, if you are using the Javascript library, the calls will look like as follow:
Creation Profile
The default
creation profile is used. You can change it using the dedicated option.
Response Handlers
You can customize the responses returned by the controllers by using custom handlers. This could be useful when you want to return additional information to your application.
There are 3 types of responses and handlers:
Creation options,
Success,
Failure.
Creation Options Handler
This handler is called during the registration of a authenticator and has to implement the interface Webauthn\Bundle\Security\Handler\CreationOptionsHandler
.
Success Handler
This handler is called when a client sends a valid assertion from the authenticator. This handler shall implement the interface Webauthn\Bundle\Security\Handler\SuccessHandler
. The default handler is Webauthn\Bundle\Service\DefaultSuccessHandler
.
Failure Handler
This handler is called when an error occurred during the process. This handler shall implement the interface Webauthn\Bundle\Security\Handler\SuccessHandler
. The default handler is Webauthn\Bundle\Service\DefaultFailureHandler
.
Last updated