Your application certainly has a user repository. Good news: there is no need to modify it!
The User Entity Repository can be completely decoupled from the user entity used by your application.
This repository should be declared as a Symfony service and shall implement Webauthn\Bundle\Repository\PublicKeyCredentialUserEntityRepositoryInterface.
Hereafter an example where the application User Repository is injected. This repository uses Doctrine and provides findOneBy* methods.
src/Repository/WebauthnUserEntityRepository.php
<?phpdeclare(strict_types=1);namespaceApp\Repository;useApp\Entity\User;useWebauthn\Bundle\Repository\PublicKeyCredentialUserEntityRepositoryInterface;useWebauthn\PublicKeyCredentialUserEntity;finalclassWebauthnUserEntityRepositoryimplementsPublicKeyCredentialUserEntityRepositoryInterface{/** * The UserRepository $userRepository is the repository * that already exists in the application */publicfunction__construct(privateUserRepository $userRepository) { }publicfunctionfindOneByUsername(string $username):?PublicKeyCredentialUserEntity {/** @varUser|null $user */ $user =$this->userRepository->findOneBy(['username'=> $username, ]);return$this->getUserEntity($user); }publicfunctionfindOneByUserHandle(string $userHandle):?PublicKeyCredentialUserEntity {/** @varUser|null $user */ $user =$this->userRepository->findOneBy(['id'=> $userHandle, ]);return$this->getUserEntity($user); }/** * Converts a Symfony User (if any) into a Webauthn User Entity */privatefunctiongetUserEntity(null|User $user):?PublicKeyCredentialUserEntity {if ($user ===null) {returnnull; }returnnewPublicKeyCredentialUserEntity( $user->getUsername(), $user->getUserIdentifier(), $user->getDisplayName(),null ); }}
Registration Capability
By default, the User Entity Repository is not able to register any user account. You can add this behaviour by implementing the following interfaces: