After the registration of an authenticator, you will get a Public Key Credential Source object. It contains all the credential data needed to perform user authentication and much more.
Each Credential Source is managed using the Public Key Credential Source Repository.
The library does not provide any concrete implementation. It is up to you to create it depending on your application constraints. This only constraint is that your repository class must implement the interface Webauthn\PublicKeyCredentialSourceRepository.
Examples
Filesystem Repository
Please don’t use this example in production! It will store credential source objects in a temporary folder.
<?phpdeclare(strict_types=1);/* * The MIT License (MIT) * * Copyright (c) 2014-2019 Spomky-Labs * * This software may be modified and distributed under the terms * of the MIT license. See the LICENSE file for details. */namespaceWebauthn\Repository;useAssert\Assertion;useDoctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;useDoctrine\Common\Persistence\ManagerRegistry;useDoctrine\ORM\EntityManagerInterface;useWebauthn\PublicKeyCredentialSource;useWebauthn\PublicKeyCredentialSourceRepositoryas PublicKeyCredentialSourceRepositoryInterface;useWebauthn\PublicKeyCredentialUserEntity;classPublicKeyCredentialSourceRepositoryimplementsPublicKeyCredentialSourceRepositoryInterface,ServiceEntityRepositoryInterface{/** * @varEntityManagerInterface */private $manager;/** * @varstring */private $class;publicfunction__construct(ManagerRegistry $registry,string $class) {Assertion::subclassOf($class,PublicKeyCredentialSource::class,sprintf('Invalid class. Must be an instance of "Webauthn\PublicKeyCredentialSource", got "%s" instead.', $class)); $manager = $registry->getManagerForClass($class);Assertion::isInstanceOf($manager,EntityManagerInterface::class,sprintf('Could not find the entity manager for class "%s". Check your Doctrine configuration to make sure it is configured to load this entity’s metadata.', $class));$this->class = $class;$this->manager = $manager; }protectedfunctiongetClass():string {return$this->class; }protectedfunctiongetEntityManager():EntityManagerInterface {return$this->manager; }publicfunctionsaveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource,bool $flush =true):void {$this->manager->persist($publicKeyCredentialSource);if ($flush) {$this->manager->flush(); } }/** * {@inheritdoc} */publicfunctionfindAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity):array { $qb =$this->manager->createQueryBuilder();return $qb->select('c')->from($this->getClass(),'c')->where('c.userHandle = :userHandle')->setParameter(':userHandle', $publicKeyCredentialUserEntity->getId())->getQuery()->execute() ; }publicfunctionfindOneByCredentialId(string $publicKeyCredentialId):?PublicKeyCredentialSource { $qb =$this->manager->createQueryBuilder();return $qb->select('c')->from($this->getClass(),'c')->where('c.publicKeyCredentialId = :publicKeyCredentialId')->setParameter(':publicKeyCredentialId',base64_encode($publicKeyCredentialId))->setMaxResults(1)->getQuery()->getOneOrNullResult() ; }}