8000 Support JWT v4 · symfony/symfony-docs@1e1ff71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e1ff71

Browse files
committed
Support JWT v4
1 parent 89e9e3a commit 1e1ff71

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mercure.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ And here is the controller::
408408
// src/Controller/DiscoverController.php
409409
namespace App\Controller;
410410

411-
use Lcobucci\JWT\Builder;
411+
use Lcobucci\JWT\Configuration;
412412
use Lcobucci\JWT\Signer\Hmac\Sha256;
413413
use Lcobucci\JWT\Signer\Key;
414414
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -423,10 +423,13 @@ And here is the controller::
423423
$hubUrl = $this->getParameter('mercure.default_hub');
424424
$this->addLink($request, new Link('mercure', $hubUrl));
425425

426-
$token = (new Builder())
427-
// set other appropriate JWT claims, such as an expiration date
426+
$key = Key\InMemory::plainText('mercure_secret_key'); // don't forget to set this parameter! Test value: !ChangeMe!
427+
$configuration = Configuration::forSymmetricSigner(new Sha256(), $key);
428+
429+
$token = $configuration->builder()
428430
->withClaim('mercure', ['subscribe' => ["http://example.com/books/1"]]) // can also be a URI template, or *
429-
->getToken(new Sha256(), new Key($this->getParameter('mercure_secret_key'))); // don't forget to set this parameter! Test value: !ChangeMe!
431+
->getToken($configuration->signer(), $configuration->signingKey())
432+
->toString();
430433

431434
$response = $this->json(['@id' => '/demo/books/1', 'availability' => 'https://schema.org/InStock']);
432435
$response->headers->set(

0 commit comments

Comments
 (0)
0