With Doctrine, you have to indicate how to store the Credential Source objects. Hereafter an example of an entity. In this example we add an entity id
and a custom field created_at
. We also indicate the repository as we will have a custom one.
As the ID must have a fixed length and because the credentialId
field of Webauthn\PublicKeyCredentialSource
hasn’t such a requirement and is a binary string, thus we need to declare our own id
field.
Do not forget to update your database schema!
To ease the integration into your application, the bundle provides a concrete class that you can extend.
In this following example, we extend that class and add a method to get all credentials for a specific user handle. Feel free to add your own methods.
We must override the method saveCredentialSource
because we may receive Webauthn\PublicKeyCredentialSource
objects instead of App\Entity\PublicKeyCredentialSource
.
This repository should be declared as a Symfony service.
With Symfony Flex, this is usually done automatically
In a Symfony application context, you usually have to manage several user entities. Thus, in the following example, the user entity class will extend the required calls and implement the interface provided by the Symfony Security component.
Feel free to add the necessary setters as well as other fields you need (creation date, last update at…).
Please note that the ID of the user IS NOT generated by Doctrine and must be a string. We highly recommend you to use UUIDs.
The following example uses Doctrine to create, persist or perform queries using the User objects created above.
This repository should be declared as a Symfony service.
With Symfony 4, this is usually done automatically