Skip to content

Commit

Permalink
fix: json serialize publickey for cache store (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Jun 1, 2022
1 parent 74546d1 commit 1b6ad1b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Services/Webauthn/CreationOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
->setAuthenticatorSelection($this->authenticatorSelectionCriteria)
->setAttestation($this->attestationConveyance);

$this->cache->put($this->cacheKey($user), $publicKey, $this->timeout);
$this->cache->put($this->cacheKey($user), $publicKey->jsonSerialize(), $this->timeout);

return $publicKey;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Services/Webauthn/CredentialAssertionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public function __invoke(User $user, array $data): bool
*/
protected function pullPublicKey(User $user): PublicKeyCredentialRequestOptions
{
return tap($this->cache->pull($this->cacheKey($user)), function ($publicKey) {
if (! $publicKey instanceof PublicKeyCredentialRequestOptions) {
Log::debug('Webauthn wrong publickKey type');
abort(404);
}
});
try {
return PublicKeyCredentialRequestOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
} catch (\Exception $e) {
Log::debug('Webauthn publickKey deserialize error', ['exception' => $e]);
abort(404);
}
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Services/Webauthn/CredentialAttestationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public function __invoke(User $user, array $data): PublicKeyCredentialSource
*/
protected function pullPublicKey(User $user): PublicKeyCredentialCreationOptions
{
return tap($this->cache->pull($this->cacheKey($user)), function ($publicKey) {
if (! $publicKey instanceof PublicKeyCredentialCreationOptions) {
Log::debug('Webauthn wrong publickKey type');
abort(404);
}
});
try {
return PublicKeyCredentialCreationOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
} catch (\Exception $e) {
Log::debug('Webauthn publickKey deserialize error', ['exception' => $e]);
abort(404);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Webauthn/RequestOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __invoke(User $user): PublicKeyCredentialRequestOptions
->setRpId($this->getRpId())
->setUserVerification($this->userVerification);

$this->cache->put($this->cacheKey($user), $publicKey, $this->timeout);
$this->cache->put($this->cacheKey($user), $publicKey->jsonSerialize(), $this->timeout);

return $publicKey;
}
Expand Down

0 comments on commit 1b6ad1b

Please sign in to comment.