Skip to content

Commit 1d1f417

Browse files
authored
fix: fix serialization (#456)
1 parent 00dfcc5 commit 1d1f417

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/Services/Webauthn/CreationOptionsFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
5151
$this->timeout
5252
);
5353

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

5658
return $publicKey;
5759
}

src/Services/Webauthn/CredentialAssertionValidator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function __invoke(User $user, array $data): bool
5353
protected function pullPublicKey(User $user): PublicKeyCredentialRequestOptions
5454
{
5555
try {
56-
return PublicKeyCredentialRequestOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
56+
$value = json_decode($this->cache->pull($this->cacheKey($user)), true, flags: JSON_THROW_ON_ERROR);
57+
58+
return PublicKeyCredentialRequestOptions::createFromArray($value);
5759
} catch (\Exception $e) {
5860
app('webauthn.log')->debug('Webauthn publickKey deserialize error', ['exception' => $e]);
5961
abort(404);

src/Services/Webauthn/CredentialAttestationValidator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function __invoke(User $user, array $data): PublicKeyCredentialSource
4848
protected function pullPublicKey(User $user): PublicKeyCredentialCreationOptions
4949
{
5050
try {
51-
return PublicKeyCredentialCreationOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
51+
$value = json_decode($this->cache->pull($this->cacheKey($user)), true, flags: JSON_THROW_ON_ERROR);
52+
53+
return PublicKeyCredentialCreationOptions::createFromArray($value);
5254
} catch (\Exception $e) {
5355
app('webauthn.log')->debug('Webauthn publicKey deserialize error', ['exception' => $e]);
5456
abort(404);

src/Services/Webauthn/RequestOptionsFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public function __invoke(User $user): PublicKeyCredentialRequestOptions
4141
$this->timeout
4242
);
4343

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

4648
return $publicKey;
4749
}

0 commit comments

Comments
 (0)