Skip to content

Commit

Permalink
fix: fix serialization (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 1, 2023
1 parent 00dfcc5 commit 1d1f417
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
$this->timeout
);

$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 @@ -41,7 +41,9 @@ public function __invoke(User $user): PublicKeyCredentialRequestOptions
$this->timeout
);

$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 1d1f417

Please sign in to comment.