user) { $this->validateUser($validation); if ($validation->request->json('response.userHandle')) { $this->validateId($validation); } } else { $this->validateId($validation); } return $next($validation); } /** * Validate the user owns the Credential if it already exists in the validation procedure. * * @param \Laragear\WebAuthn\Assertion\Validator\AssertionValidation $validation * @return void */ protected function validateUser(AssertionValidation $validation): void { // @phpstan-ignore-next-line if ($validation->credential->authenticatable()->isNot($validation->user)) { throw AssertionException::make('User is not owner of the stored credential.'); } } /** * Validate the user ID of the response. * * @param \Laragear\WebAuthn\Assertion\Validator\AssertionValidation $validation * @return void */ protected function validateId(AssertionValidation $validation): void { $handle = $validation->request->json('response.userHandle'); if (! $handle || ! hash_equals(Uuid::fromString($validation->credential->user_id)->getHex()->toString(), $handle)) { throw AssertionException::make('User ID is not owner of the stored credential.'); } } }