json_encode() of PublicKeyCredentialRequestOptions fails
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 82/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- php
- Domain
- documentation
Research direction
Read the authentication guide linked in the issue and compare its serialization instructions with the maintainer’s reply and the referenced serializer page. Update the guide to explain that json_encode() no longer works for these objects in 5.0 and direct readers to the Serializer; done when the example matches the supported approach.
Written by the indexing model from the issue text.
Description
Version(s) affected
5.0
Description
Works in 4.9 but not 5.0: json_encode(\Webauthn\PublicKeyCredentialRequestOptions::create(random_bytes(32), allowCredentials: []))
I need to json_encode() it to submit the request to my site via a JSON-RPC endpoint.
The docs still say:
The PublicKeyCredentialRequestOptions object is designed to be easily serialized into a JSON object. This will ease the integration into an HTML page or through an API endpoint.
How to reproduce
With 4.9, I was using this code:
$public_key_credential_request_options = PublicKeyCredentialRequestOptions::create(
$this->webauthn->createChallenge(),
allowCredentials: $allowed_credentials,
);
$this->tempstore->set(self::TEMP_STORE_REQUEST_OPTIONS, $public_key_credential_request_options);
$stringified_json = json_encode($public_key_credential_request_options);
if (is_string($stringified_json)) {
}
After upgrading to 5.0, this fails because the value of json_encode() is false.
Possible Solution
No response
Additional Context
No response
From the original thread
albanx — 2024-10-28
I had the same issue today, the only way to make it work is to serialize it and send as JSON string:
This is the example in the docs:
use Symfony\Component\Serializer\Encoder\JsonEncode; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; // The serializer is the same as the one created in the previous pages $jsonObject = $serializer->serialize( $publicKeyCredentialCreationOptions, 'json', [ // Optional AbstractObjectNormalizer::SKIP_NULL_VALUES => true, JsonEncode::OPTIONS => JSON_THROW_ON_ERROR, ] );
Spomky — 2024-10-28
After upgrading to 5.0, this fails because the value of json_encode() is false.
Indeed,
json_encodeshould not be used as in 5.0.+ the objects do not implement theJsonSerializableinterface.
Please use the Serializer instead.
ptmkenny — 2024-10-29
Thank you for the updates. Also,
Webauthn\PublicKeyCredentialSource::jsonSerialize()was removed, but this isn't listed in the migration docs.
Copied from web-auth/doc#32, opened by @ptmkenny on 2024-10-25. The documentations of Slabs now share one site and one repository, and the former one is being retired — nothing was lost, and this is where the thread continues.
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 34m
- Merged PRs (30d)
- 40
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Spomky-Labs/docs
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Spomky-Labs/docs#27 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 67/100
Spomky-Labs/docs#26 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 74/100
Spomky-Labs/docs#25 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
Spomky-Labs/docs#23 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 45/100
Spomky-Labs/docs#24 ·
Maintainers usually reply within 1 day
All issues in Spomky-Labs/docs
Similar issues
-
backend enhancement priority:P3
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
geolens-io/geolens#4161 ·
Maintainers usually reply within 1 day
-
pkg:clai2
Difficulty 1/5 Under an hour Newbie friendliness 75/100
pydantic/pydantic-ai#14845 ·
Maintainers usually reply within 1 day
-
Add a languageOpengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
LearningCircuit/local-deep-research#9272 ·
Maintainers usually reply within 1 day
-
documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
patrickballard/wheelgap#783 ·