json_encode() of PublicKeyCredentialRequestOptions fails

Aperta Adatta ai principianti
#22 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
82/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
documentation

Direzione di ricerca

Leggi la guida all’autenticazione collegata nell’issue e confronta le istruzioni di serializzazione con la risposta del maintainer e la pagina del serializzatore citata. Aggiorna la guida per spiegare che json_encode() non funziona più con questi oggetti nella versione 5.0 e indirizza i lettori al Serializer; il lavoro è completato quando l’esempio corrisponde all’approccio supportato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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_encode should not be used as in 5.0.+ the objects do not implement the JsonSerializable interface.
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.

Lingua principale
Python
Stelle
0
Fork
0
Merge medio
34m
PR unite (30g)
40

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Spomky-Labs/docs

Tutte le issue di Spomky-Labs/docs

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.