Closed akubima closed 11 months ago
@ppmint1 it looks like some serialization does not happen automatically anymore in 4.7.1
I my case, doing it manually gets the things working again.
In the registration controller, where I create the PublicKeyCredentialCreationOptions
and serialize them:
$serializedOptions = $publicKeyCredentialCreationOptions->jsonSerialize()
I have to serialize the 'parts' as follows:
$serializedOptions['rp'] = $serializedOptions['rp']->jsonSerialize();
$serializedOptions['user'] = $serializedOptions['user']->jsonSerialize();
$serializedOptions['extensions'] = $serializedOptions['extensions']->jsonSerialize();
$serializedOptions['authenticatorSelection'] = $serializedOptions['authenticatorSelection']->jsonSerialize();
In the login controller, I had to do basically the same with the PublicKeyCredentialDescriptor
:
$allowedCredentials = [
...$authenticators,
...[
PublicKeyCredentialSource::createFromArray($publicKey)->getPublicKeyCredentialDescriptor()->jsonSerialize()
]
];
$publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::create(
challenge: $challenge,
allowCredentials: $allowedCredentials,
);
$serializedOptions = $publicKeyCredentialRequestOptions->jsonSerialize();
$serializedOptions = $publicKeyCredentialCreationOptions->jsonSerialize()
🤔 humm. Why are you using $serializedOptions->jsonSerialize();
instead of json_encode($serializedOptions);
?
Edit: The goal of the method jsonSerialize
that comes from the interface JsonSerializable
is to customize the result of the method json_encode
. It is not supposed to but called directly.
Why are you using $serializedOptions->jsonSerialize(); instead of json_encode($serializedOptions);?
Hmmm, never thought about it to be honest. Started with an implementation where jsonSerialize()
was used ....
But good point, thanks!
Closing as answered. Feel free to open it again if necessary. Regards.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Version(s) affected
4.7.1
Description
"Webauthn\AuthenticatorSelectionCriteria::createFromArray(): Argument #1 ($json) must be of type array, Webauthn\AuthenticatorSelectionCriteria given, called in /var/www/projects/webauthn/vendor/web-auth/webauthn-lib/src/PublicKeyCredentialCreationOptions.php on line 276"
How to reproduce
I use https://github.com/asbiin/laravel-webauthn (but I believed that this error comes from the webauth-lib) and https://simplewebauthn.dev/docs/packages/browser want to register a new key but got that error (must be type of array).
Here is my JavaScript code
Additional Context