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
Copy file name to clipboardExpand all lines: articles/azure-web-pubsub/howto-develop-eventhandler.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,30 +22,34 @@ The data sending from the service to the server is always in CloudEvents `binary
22
22
23
23
## Upstream and Validation
24
24
25
-
When configuring the webhook endpoint, the URL can use `{event}` parameter to define a URL template. The service calculates the value of the webhook URL dynamically when the client request comes in. For example, when a request `/client/hubs/chat` comes in, with a configured event handler URL pattern `http://host.com/api/{event}` for hub `chat`, when the client connects, it will first POST to this URL: `http://host.com/api/connect`. This can be useful when a PubSub WebSocket client sends custom events, that the event handler helps dispatch different events to different upstream. Note that the `{event}` parameter is not allowed in the URL domain name.
25
+
When configuring the webhook endpoint, the URL can use `{event}` parameter to define a URL template. The service calculates the value of the webhook URL dynamically when the client request comes in. For example, when a request `/client/hubs/chat` comes in, with a configured event handler URL pattern `http://host.com/api/{event}` for hub `chat`, when the client connects, it will first POST to this URL: `http://host.com/api/connect`. The parameter can be useful when a PubSub WebSocket client sends custom events, that the event handler helps dispatch different events to different upstream. Note that the `{event}` parameter is not allowed in the URL domain name.
26
26
27
-
When setting up the event handler upstream through Azure portal or CLI, the service follows the [CloudEvents Abuse Protection](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#4-abuse-protection) to validate the upstream webhook. Every registered upstream webhook URL will be validated by this mechanism. The `WebHook-Request-Origin` request header is set to the service domain name `xxx.webpubsub.azure.com`, and it expects the response having header `WebHook-Allowed-Origin` to contain this domain name or `*`.
27
+
When setting up the event handler upstream through Azure portal or CLI, the service follows the [CloudEvents Abuse Protection](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#4-abuse-protection) to validate the upstream webhook. Every registered upstream webhook URL will be validated by this mechanism. The `WebHook-Request-Origin` request header is set to the service domain name `xxx.webpubsub.azure.com`, and it expects the response to have a header `WebHook-Allowed-Origin` to contain this domain name or `*`.
28
28
29
-
When doing the validation, the `{event}` parameter is resolved to `validate`. For example, when trying to set the URL to `http://host.com/api/{event}`, the service tries to **OPTIONS** a request to `http://host.com/api/validate` and only when the response is valid the configure can be set successfully.
29
+
When doing the validation, the `{event}` parameter is resolved to `validate`. For example, when trying to set the URL to `http://host.com/api/{event}`, the service will try to **OPTIONS** a request to `http://host.com/api/validate`. And only when the response is valid, the configuration can be set successfully.
30
30
31
31
For now, we do not support [WebHook-Request-Rate](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#414-webhook-request-rate) and [WebHook-Request-Callback](https://github.com/cloudevents/spec/blob/v1.0/http-webhook.md#413-webhook-request-callback).
32
32
33
33
## Authentication between service and webhook
34
34
35
35
- Anonymous mode
36
36
- Simple Auth with `?code=<code>` is provided through the configured Webhook URL as query parameter.
37
-
- Use AAD Auth, check [here](howto-use-managed-identity.md) for details.
37
+
- Use Azure Active Directory(Azure AD) authentication, check [here](howto-use-managed-identity.md) for details.
38
38
- Step1: Enable Identity for the Web PubSub service
39
39
- Step2: Select from existing AAD application that stands for your webhook web app
40
40
41
41
## Configure event handler
42
42
43
43
### Configure through Azure portal
44
44
45
-
Find your Azure Web PubSub service from **Azure portal**. Navigate to **Settings** and enter your hub-name. Then click**Add** to configure your serverside webhook URL. Don't forget to click **Save**when finish.
45
+
Find your Azure Web PubSub service from **Azure portal**. Navigate to **Settings**. Then select**Add** to configure your server-side webhook URL. For an existing hub configuration, select **...**on right side will navigate to the same editing page.
46
46
47
47
:::image type="content" source="media/quickstart-serverless/set-event-handler.png" alt-text="Screenshot of setting the event handler.":::
48
48
49
+
Then in the below editing page, you'd need to configure hub name, server webhook URL, and select `user` and `system` events you'd like to subscribe. Finally select **Save** when everything is done.
50
+
51
+
:::image type="content" source="media/quickstart-serverless/edit-event-handler.png" alt-text="Screenshot of editing the event handler.":::
52
+
49
53
### Configure through Azure CLI
50
54
51
55
Use the Azure CLI [**az webpubsub hub**](/cli/azure/webpubsub/hub) group commands to configure the event handler settings.
3. Create an `index`functiontoread and host a static web page for clients.
@@ -204,6 +204,10 @@ In this tutorial, you learn how to:
204
204
return connection;
205
205
}
206
206
```
207
+
- Add below `using` statements in header to resolve required dependencies.
208
+
```c#
209
+
using Microsoft.Azure.WebJobs.Extensions.WebPubSub;
210
+
```
207
211
208
212
5. Create a `notification`functionto generate notifications with `TimerTrigger`.
209
213
```bash
@@ -265,6 +269,11 @@ In this tutorial, you learn how to:
265
269
return value.ToString("0.000");
266
270
}
267
271
```
272
+
- Add below `using` statements in header to resolve required dependencies.
273
+
```c#
274
+
using Microsoft.Azure.WebJobs.Extensions.WebPubSub;
275
+
using Microsoft.Azure.WebPubSub.Common;
276
+
```
268
277
269
278
6. Add the client single page `index.html`in the project root folder and copy content as below.
270
279
```html
@@ -310,14 +319,14 @@ In this tutorial, you learn how to:
310
319
311
320
:::image type="content" source="media/quickstart-serverless/copy-connection-string.png" alt-text="Screenshot of copying the Web PubSub connection string.":::
312
321
313
-
Run command below in the functionfolder to set the service connection string. Replace `<connection-string`> with your value as needed.
322
+
Run command below in the functionfolder to set the service connection string. Replace `<connection-string>` with your value as needed.
>`TimerTrigger` used in the sample has dependency on Azure Storage, but you can use local storage emulator when the Function is running locally. If you got some error like `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.` You need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md).
329
+
>`TimerTrigger` used in the sample has dependency on Azure Storage, but you can use local storage emulator when the Function is running locally. If you got some error like `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.`, you'll need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md).
321
330
322
331
Now you're able to run your localfunctionbycommand below.
0 commit comments