Skip to content

Commit 925873e

Browse files
committed
Refactor authenticator response identification logic
The logic for identifying the type of Authenticator Response has been simplified. Instead of checking for multiple array keys in a data object, we now simply check for the presence of either 'attestationObject' or 'signature'. This refactoring leads to cleaner and more maintainable code.
1 parent d296fde commit 925873e

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

src/Denormalizer/AuthenticatorResponseDenormalizer.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@ final class AuthenticatorResponseDenormalizer implements DenormalizerInterface,
2020
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
2121
{
2222
$realType = match (true) {
23-
array_key_exists('attestationObject', $data) && ! array_key_exists(
24-
'signature',
25-
$data
26-
) => AuthenticatorAttestationResponse::class,
27-
array_key_exists('authenticatorData', $data) && array_key_exists(
28-
'signature',
29-
$data
30-
) => AuthenticatorAssertionResponse::class,
23+
array_key_exists('attestationObject', $data) => AuthenticatorAttestationResponse::class,
24+
array_key_exists('signature', $data) => AuthenticatorAssertionResponse::class,
3125
default => throw InvalidDataException::create($data, 'Unable to create the response object'),
3226
};
3327

src/PublicKeyCredentialLoader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@ private function createResponse(array $response): AuthenticatorResponse
153153
return $this->serializer->deserialize($response, AuthenticatorResponse::class, 'json');
154154
}
155155
switch (true) {
156-
case ! array_key_exists('authenticatorData', $response) && ! array_key_exists('signature', $response):
156+
case array_key_exists('attestationObject', $response):
157157
$attestationObject = $this->attestationObjectLoader->load($response['attestationObject']);
158158

159159
return AuthenticatorAttestationResponse::create(CollectedClientData::createFormJson(
160160
$response['clientDataJSON']
161161
), $attestationObject, $transports);
162-
case array_key_exists('authenticatorData', $response) && array_key_exists('signature', $response):
162+
case array_key_exists('signature', $response):
163163
$authDataLoader = AuthenticatorDataLoader::create();
164-
$authData = Base64UrlSafe::decodeNoPadding($response['authenticatorData']);
164+
$authData = Base64UrlSafe::decodeNoPadding($response['authenticatorData'] ?? '');
165165
$authenticatorData = $authDataLoader->load($authData);
166166

167167
try {

0 commit comments

Comments
 (0)