Skip to content

Commit 1b6ad1b

Browse files
authored
fix: json serialize publickey for cache store (#385)
1 parent 74546d1 commit 1b6ad1b

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/Services/Webauthn/CreationOptionsFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
6868
->setAuthenticatorSelection($this->authenticatorSelectionCriteria)
6969
->setAttestation($this->attestationConveyance);
7070

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

7373
return $publicKey;
7474
}

src/Services/Webauthn/CredentialAssertionValidator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ public function __invoke(User $user, array $data): bool
7373
*/
7474
protected function pullPublicKey(User $user): PublicKeyCredentialRequestOptions
7575
{
76-
return tap($this->cache->pull($this->cacheKey($user)), function ($publicKey) {
77-
if (! $publicKey instanceof PublicKeyCredentialRequestOptions) {
78-
Log::debug('Webauthn wrong publickKey type');
79-
abort(404);
80-
}
81-
});
76+
try {
77+
return PublicKeyCredentialRequestOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
78+
} catch (\Exception $e) {
79+
Log::debug('Webauthn publickKey deserialize error', ['exception' => $e]);
80+
abort(404);
81+
}
8282
}
8383

8484
/**

src/Services/Webauthn/CredentialAttestationValidator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ public function __invoke(User $user, array $data): PublicKeyCredentialSource
7070
*/
7171
protected function pullPublicKey(User $user): PublicKeyCredentialCreationOptions
7272
{
73-
return tap($this->cache->pull($this->cacheKey($user)), function ($publicKey) {
74-
if (! $publicKey instanceof PublicKeyCredentialCreationOptions) {
75-
Log::debug('Webauthn wrong publickKey type');
76-
abort(404);
77-
}
78-
});
73+
try {
74+
return PublicKeyCredentialCreationOptions::createFromArray($this->cache->pull($this->cacheKey($user)));
75+
} catch (\Exception $e) {
76+
Log::debug('Webauthn publickKey deserialize error', ['exception' => $e]);
77+
abort(404);
78+
}
7979
}
8080

8181
/**

src/Services/Webauthn/RequestOptionsFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __invoke(User $user): PublicKeyCredentialRequestOptions
4545
->setRpId($this->getRpId())
4646
->setUserVerification($this->userVerification);
4747

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

5050
return $publicKey;
5151
}

0 commit comments

Comments
 (0)