You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use `iri` (iriConverter) and `escape` (rawurlencode) functions to add an alternative topic, in order to restrict a subscriber with `topic_selector` to receive only publications that are authorized (partner match).
134
+
135
+
> Let's say that a subscriber wants to receive updates concerning all book resources it has access to. The subscriber can use the topic selector <https://example.com/books/{id}> as value of the topic query parameter.
136
+
> Adding this same URI template to the mercure.subscribe claim of the JWS presented by the subscriber to the hub would allow this subscriber to receive all updates for all book resources. It is not what we want here: this subscriber is only authorized to access some of these resources.
137
+
>
138
+
> To solve this problem, the mercure.subscribe claim could contain a topic selector such as: <https://example.com/users/foo/{?topic}>.
139
+
>
140
+
> The publisher could then take advantage of the previously described behavior by publishing a private update having <https://example.com/books/1> as canonical topic and <https://example.com/users/foo/?topic=https%3A%2F%2Fexample.com%2Fbooks%2F1> as alternate topic.
141
+
>
142
+
> —<https://mercure.rocks/spec#subscribers>
143
+
144
+
Below is an example using the `topics` option:
145
+
146
+
```php
147
+
<?php
148
+
// api/src/Entity/Book.php
149
+
150
+
namespace App\Entity;
151
+
152
+
use ApiPlatform\Core\Annotation\ApiResource;
153
+
use ApiPlatform\Core\Api\UrlGeneratorInterface;
154
+
use App\Entity\User;
155
+
156
+
#[ApiResource(
157
+
mercure: [
158
+
'private' => true,
159
+
// the '@=' prefix is required when using expressions for arguments in topics
0 commit comments