Skip to content

Commit

Permalink
fix: fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Oct 1, 2023
1 parent 6c8e089 commit 0975749
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Services/Webauthn/CreationOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
->setAuthenticatorSelection($this->authenticatorSelectionCriteria)
->setAttestation($this->attestationConveyance);

$this->cache->put($this->cacheKey($user), $publicKey->jsonSerialize(), $this->timeout);
$value = json_encode($publicKey, flags: JSON_THROW_ON_ERROR);

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

return $publicKey;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Services/Webauthn/CredentialAssertionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function __invoke(User $user, array $data): bool
protected function pullPublicKey(User $user): PublicKeyCredentialRequestOptions
{
try {
return PublicKeyCredentialRequestOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
$value = json_decode($this->cache->pull($this->cacheKey($user)), true, flags: JSON_THROW_ON_ERROR);

return PublicKeyCredentialRequestOptions::createFromArray($value);
} catch (\Exception $e) {
app('webauthn.log')->debug('Webauthn publickKey deserialize error', ['exception' => $e]);
abort(404);
Expand Down
4 changes: 3 additions & 1 deletion src/Services/Webauthn/CredentialAttestationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function __invoke(User $user, array $data): PublicKeyCredentialSource
protected function pullPublicKey(User $user): PublicKeyCredentialCreationOptions
{
try {
return PublicKeyCredentialCreationOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
$value = json_decode($this->cache->pull($this->cacheKey($user)), true, flags: JSON_THROW_ON_ERROR);

return PublicKeyCredentialCreationOptions::createFromArray($value);
} catch (\Exception $e) {
app('webauthn.log')->debug('Webauthn publicKey deserialize error', ['exception' => $e]);
abort(404);
Expand Down
4 changes: 3 additions & 1 deletion src/Services/Webauthn/RequestOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public function __invoke(User $user): PublicKeyCredentialRequestOptions
->setRpId($this->getRpId())
->setUserVerification($this->userVerification);

$this->cache->put($this->cacheKey($user), $publicKey->jsonSerialize(), $this->timeout);
$value = json_encode($publicKey, flags: JSON_THROW_ON_ERROR);

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

return $publicKey;
}
Expand Down

0 comments on commit 0975749

Please sign in to comment.