Skip to content

Commit 8b67d72

Browse files
committed
minor #13812 Update mercure.rst (Myystigri)
This PR was merged into the 5.1 branch. Discussion ---------- Update mercure.rst Update cookie configuration to match new symfony 5.1 methods https://symfony.com/doc/current/components/http_foundation.html#setting-cookies <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 0be6f2e Update mercure.rst
2 parents 2f37ac1 + 0be6f2e commit 8b67d72

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mercure.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ And here is the controller::
402402
use Lcobucci\JWT\Signer\Hmac\Sha256;
403403
use Lcobucci\JWT\Signer\Key;
404404
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
405+
use Symfony\Component\HttpFoundation\Cookie;
405406
use Symfony\Component\HttpFoundation\Request;
406407
use Symfony\Component\HttpFoundation\Response;
407408
use Symfony\Component\WebLink\Link;
@@ -419,10 +420,14 @@ And here is the controller::
419420
->getToken(new Sha256(), new Key($this->getParameter('mercure_secret_key'))); // don't forget to set this parameter! Test value: !ChangeMe!
420421

421422
$response = $this->json(['@id' => '/demo/books/1', 'availability' => 'https://schema.org/InStock']);
422-
$response->headers->set(
423-
'set-cookie',
424-
sprintf('mercureAuthorization=%s; path=/.well-known/mercure; secure; httponly; SameSite=strict', $token)
425-
);
423+
$cookie = Cookie::create('mercureAuthorization')
424+
->withValue($token)
425+
->withPath('/.well-known/mercure')
426+
->withSecure(true)
427+
->withHttpOnly(true)
428+
->withSameSite('strict')
429+
;
430+
$response->headers->setCookie($cookie);
426431

427432
return $response;
428433
}

0 commit comments

Comments
 (0)