Skip to content

Commit 7496149

Browse files
committed
review
1 parent 142a6f9 commit 7496149

File tree

1 file changed

+50
-57
lines changed

1 file changed

+50
-57
lines changed

mercure.rst

+50-57
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,16 @@ This token must be signed with the same secret key as the one used by the Hub to
111111
This secret key must be stored in the ``MERCURE_JWT_SECRET`` environment variable.
112112
MercureBundle will use it to automatically generate and sign the needed JWTs.
113113

114-
If you don't want to use the provided environment variables,
115-
use the following configuration:
114+
In addition to these environment variables,
115+
MercureBundle provides a more advanced configuration configuration:
116+
117+
* ``secret``: the key to use to sign the JWT
118+
* ``publish``: a list of topics to allow publishing to when generating the JWT
119+
* ``subscribe``: a list of topics to allow subscribing to when generating the JWT
120+
* ``algorithm``: The algorithm to use to sign the JWT
121+
* ``provider``: The ID of a service to call to provide the JWT
122+
* ``factory``: The ID of a service to call to create the JWT
123+
* ``value``: the raw JWT to use (all other options will be ignored)
116124

117125
.. configuration-block::
118126

@@ -125,6 +133,12 @@ use the following configuration:
125133
url: https://mercure-hub.example.com/.well-known/mercure
126134
jwt:
127135
secret: '!ChangeMe!'
136+
publish: ['foo', 'https://example.com/foo']
137+
subscribe: ['bar', 'https://example.com/bar']
138+
algorithm: 'hmac.sha256'
139+
provider: 'My\Provider'
140+
factory: 'My\Factory'
141+
value: 'my.jwt'
128142
129143
.. code-block:: xml
130144
@@ -135,7 +149,18 @@ use the following configuration:
135149
name="default"
136150
url="https://mercure-hub.example.com/.well-known/mercure"
137151
>
138-
<jwt secret="!ChangeMe!"/>
152+
<jwt
153+
secret="!ChangeMe!"
154+
algorithm="hmac.sha256"
155+
provider="My\Provider"
156+
factory="My\Factory"
157+
value="my.jwt"
158+
>
159+
<publish>foo</publish>
160+
<publish>https://example.com/foo</publish>
161+
<subscribe>bar</subscribe>
162+
<subscribe>https://example.com/bar</subscribe>
163+
</jwt>
139164
</hub>
140165
</config>
141166
@@ -148,68 +173,32 @@ use the following configuration:
148173
'url' => 'https://mercure-hub.example.com/.well-known/mercure',
149174
'jwt' => [
150175
'secret' => '!ChangeMe!',
176+
'publish' => ['foo', 'https://example.com/foo'],
177+
'subscribe' => ['bar', 'https://example.com/bar'],
178+
'algorithm' => 'hmac.sha256',
179+
'provider' => 'My\Provider',
180+
'factory' => 'My\Factory',
181+
'value' => 'my.jwt',
151182
],
152183
],
153184
],
154185
]);
155186
156-
Alternatively, it's also possible to pass directly the JWT to use:
157-
158-
.. configuration-block::
159-
160-
.. code-block:: yaml
161-
162-
# config/packages/mercure.yaml
163-
mercure:
164-
hubs:
165-
default:
166-
url: https://mercure-hub.example.com/.well-known/mercure
167-
jwt:
168-
value: 'the.JWT'
169-
170-
.. code-block:: xml
171-
172-
<!-- config/packages/mercure.xml -->
173-
<?xml version="1.0" encoding="UTF-8" ?>
174-
<config>
175-
<hub
176-
name="default"
177-
url="https://mercure-hub.example.com/.well-known/mercure"
178-
>
179-
<jwt value="the.JWT"/>
180-
</hub>
181-
</config>
182-
183-
.. code-block:: php
184-
185-
// config/packages/mercure.php
186-
$container->loadFromExtension('mercure', [
187-
'hubs' => [
188-
'default' => [
189-
'url' => 'https://mercure-hub.example.com/.well-known/mercure',
190-
'jwt' => [
191-
'value' => 'the.JWT',
192-
],
193-
],
194-
],
195-
]);
196-
187+
.. tip::
197188

198-
The JWT payload must contain at least the following structure to be allowed to
199-
publish:
189+
The JWT payload must contain at least the following structure to be allowed to
190+
publish:
200191

201-
.. code-block:: json
192+
.. code-block:: json
202193
203-
{
204-
"mercure": {
205-
"publish": []
194+
{
195+
"mercure": {
196+
"publish": []
197+
}
206198
}
207-
}
208-
209-
Because the array is empty, the Symfony app will only be authorized to publish
210-
public updates (see the authorization_ section for further information).
211199
212-
.. tip::
200+
Because the array is empty, the Symfony app will only be authorized to publish
201+
public updates (see the authorization_ section for further information).
213202

214203
The jwt.io website is a convenient way to create and sign JWTs.
215204
Checkout this `example JWT`_, that grants publishing rights for all *topics*
@@ -364,7 +353,7 @@ by using the ``AbstractController::addLink`` helper method::
364353
{
365354
public function discover(Request $request, Discovery $discovery): JsonResponse
366355
{
367-
// Link: <http://hub.example.com/.well-known/mercure>; rel="mercure"
356+
// Link: <https://hub.example.com/.well-known/mercure>; rel="mercure"
368357
$discovery->addLink($request);
369358

370359
return $this->json([
@@ -380,7 +369,7 @@ and to subscribe to it:
380369
.. code-block:: javascript
381370
382371
// Fetch the original resource served by the Symfony web API
383-
fetch('/books/1') // Has Link: <http://hub.example.com/.well-known/mercure>; rel="mercure"
372+
fetch('/books/1') // Has Link: <https://hub.example.com/.well-known/mercure>; rel="mercure"
384373
.then(response => {
385374
// Extract the hub URL from the Link header
386375
const hubUrl = response.headers.get('Link').match(/<([^>]+)>;\s+rel=(?:mercure|"[^"]*mercure[^"]*")/)[1];
@@ -688,6 +677,10 @@ sent:
688677
mercure.hub.default:
689678
class: App\Tests\Functional\Stub\HubStub
690679
680+
As MercureBundle support multiple hubs, you may have to replace
681+
the other service definitions accordingly.
682+
683+
691684
.. tip::
692685

693686
Symfony Panther has `a feature to test applications using Mercure`_.

0 commit comments

Comments
 (0)