Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH PHP 8.1 compatibility #107

Merged
merged 1 commit into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/CredentialRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCre

return array_map(function ($credentialComposite) {
return $credentialComposite['source'];
}, $this->credentials);
}, $this->credentials ?? []);
}

public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource): void
Expand Down Expand Up @@ -156,7 +156,7 @@ protected function setCredentials(array $credentials): void
$this->credentials = array_map(function ($data) {
$data['source'] = PublicKeyCredentialSource::createFromArray($data['source']);
return $data;
}, $credentials);
}, $credentials ?? []);
}

/**
Expand All @@ -167,7 +167,7 @@ protected function setCredentials(array $credentials): void
*/
protected function getCredentialIDRef(string $credentialID): string
{
return base64_encode($credentialID);
return base64_encode($credentialID ?? '');
}

/**
Expand Down Expand Up @@ -230,6 +230,6 @@ public function serialize()
*/
public function unserialize($serialized)
{
$this->__unserialize(json_decode($serialized, true));
$this->__unserialize(json_decode($serialized ?? '', true));
}
}
2 changes: 1 addition & 1 deletion src/CredentialRepositoryProviderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function getCredentialRepository(

if ($registeredMethod) {
$credentialRepository = CredentialRepository::fromArray(
(array) json_decode($registeredMethod->Data, true),
(array) json_decode($registeredMethod->Data ?? '', true),
(string) $member->ID
);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function register(HTTPRequest $request, StoreInterface $store): Result
$attestationStatementSupportManager = $this->getAttestationStatementSupportManager($decoder);
$attestationObjectLoader = $this->getAttestationObjectLoader($attestationStatementSupportManager, $decoder);
$publicKeyCredentialLoader = $this->getPublicKeyCredentialLoader($attestationObjectLoader, $decoder);
$publicKeyCredential = $publicKeyCredentialLoader->load(base64_decode($data['credentials']));
$publicKeyCredential = $publicKeyCredentialLoader->load(base64_decode($data['credentials'] ?? ''));
$response = $publicKeyCredential->getResponse();

if (!$response instanceof AuthenticatorAttestationResponse) {
Expand Down Expand Up @@ -226,7 +226,7 @@ protected function getRelyingPartyEntity(): PublicKeyCredentialRpEntity
{
// Relying party entity ONLY allows domains or subdomains. Remove ports or anything else that isn't already.
// See https://github.com/web-auth/webauthn-framework/blob/v1.2.2/doc/webauthn/PublicKeyCredentialCreation.md#relying-party-entity
$host = parse_url(Director::host(), PHP_URL_HOST);
$host = parse_url(Director::host() ?? '', PHP_URL_HOST);

return new PublicKeyCredentialRpEntity(
(string) SiteConfig::current_site_config()->Title,
Expand Down
6 changes: 3 additions & 3 deletions src/VerifyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function verify(HTTPRequest $request, StoreInterface $store, RegisteredMe
$attestationObjectLoader = $this->getAttestationObjectLoader($attestationStatementSupportManager, $decoder);
$publicKeyCredential = $this
->getPublicKeyCredentialLoader($attestationObjectLoader, $decoder)
->load(base64_decode($data['credentials']));
->load(base64_decode($data['credentials'] ?? ''));

$response = $publicKeyCredential->getResponse();
if (!$response instanceof AuthenticatorAssertionResponse) {
Expand Down Expand Up @@ -154,13 +154,13 @@ protected function getCredentialRequestOptions(
$validCredentials = $this->getCredentialRepository($store, $registeredMethod)
->findAllForUserEntity($this->getUserEntity($store->getMember()));

if (!count($validCredentials)) {
if (!count($validCredentials ?? [])) {
throw new AuthenticationFailedException('User does not appear to have any credentials loaded for webauthn');
}

$descriptors = array_map(function (PublicKeyCredentialSource $source) {
return $source->getPublicKeyCredentialDescriptor();
}, $validCredentials);
}, $validCredentials ?? []);

$options = new PublicKeyCredentialRequestOptions(random_bytes(32), 40000);
$options->allowCredentials($descriptors);
Expand Down