Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Models/WebauthnKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WebauthnKey extends Model
/**
* The attributes that aren't mass assignable.
*
* @var string[]|bool
* @var array<string>
*/
protected $guarded = ['id'];

Expand Down
4 changes: 3 additions & 1 deletion src/Services/Webauthn.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ public static function enabled(User $user): bool

/**
* Test if the user can register a new key.
*
* @psalm-suppress PossiblyUnusedParam
*/
public static function canRegister(User $user): bool
{
return static::webauthnEnabled() && (! static::enabled($user) || static::check());
return static::webauthnEnabled();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Services/Webauthn/CreationOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function __construct(
Config $config,
protected PublicKeyCredentialRpEntity $publicKeyCredentialRpEntity,
protected AuthenticatorSelectionCriteria $authenticatorSelectionCriteria,
protected CoseAlgorithmManager $algorithmManager
protected CoseAlgorithmManager $algorithmManager,
protected CredentialRepository $repository
) {
parent::__construct($request, $cache, $config);
$this->attestationConveyance = $config->get('webauthn.attestation_conveyance', 'none');
Expand Down Expand Up @@ -82,6 +83,6 @@ private function createCredentialParameters(): array
*/
protected function getExcludedCredentials(User $user): array
{
return CredentialRepository::getRegisteredKeys($user);
return $this->repository->getRegisteredKeys($user);
}
}
6 changes: 3 additions & 3 deletions src/Services/Webauthn/CredentialRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CredentialRepository
*
* @return Collection<array-key,PublicKeyCredentialSource>
*/
protected static function getAllRegisteredKeys(int|string $userId): Collection
protected function getAllRegisteredKeys(int|string $userId): Collection
{
return (Webauthn::model())::where('user_id', $userId)
->get()
Expand All @@ -28,9 +28,9 @@ protected static function getAllRegisteredKeys(int|string $userId): Collection
*
* @return array<array-key,PublicKeyCredentialDescriptor>
*/
public static function getRegisteredKeys(User $user): array
public function getRegisteredKeys(User $user): array
{
return static::getAllRegisteredKeys($user->getAuthIdentifier())
return $this->getAllRegisteredKeys($user->getAuthIdentifier())
->map
->getPublicKeyCredentialDescriptor()
->toArray();
Expand Down
5 changes: 3 additions & 2 deletions src/Services/Webauthn/RequestOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public function __construct(
Request $request,
Cache $cache,
Config $config,
protected PublicKeyCredentialRpEntity $publicKeyCredentialRpEntity
protected PublicKeyCredentialRpEntity $publicKeyCredentialRpEntity,
protected CredentialRepository $repository
) {
parent::__construct($request, $cache, $config);
$this->userVerification = self::getUserVerification($config);
Expand Down Expand Up @@ -60,7 +61,7 @@ private static function getUserVerification(Config $config): ?string
*/
private function getAllowedCredentials(?User $user): array
{
return $user !== null ? CredentialRepository::getRegisteredKeys($user) : [];
return $user !== null ? $this->repository->getRegisteredKeys($user) : [];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Services/Webauthn/CredentialRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function it_returns_an_empty_array_when_no_keys_are_registered()

$this->assertEmpty(WebauthnKey::all());

$this->assertEquals([], CredentialRepository::getRegisteredKeys($user));
$this->assertEquals([], (new CredentialRepository)->getRegisteredKeys($user));
}

#[Test]
Expand All @@ -34,7 +34,7 @@ public function it_returns_an_array_with_the_keys()
'credentialId' => '1',
]);

$keys = CredentialRepository::getRegisteredKeys($user);
$keys = (new CredentialRepository)->getRegisteredKeys($user);
$this->assertCount(1, $keys);
$this->assertEquals('{"type":"public-key","id":"1","transports":[]}', json_encode($keys[0], JSON_THROW_ON_ERROR));
}
Expand Down
Loading