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
# SignalR Service input binding for Azure Functions
14
14
15
-
Before a client can connect to Azure SignalR Service, it must retrieve the service endpoint URL and a valid access token. The *SignalRConnectionInfo* input binding produces the SignalR Service endpoint URL and a valid token that are used to connect to the service. Because the token is time-limited and can be used to authenticate a specific user to a connection, you should not cache the token or share it between clients. An HTTP trigger using this binding can be used by clients to retrieve the connection information.
16
-
17
-
For more information on how this binding is used to create a "negotiate" function that can be consumed by a SignalR client SDK, see the [Azure Functions development and configuration article](../azure-signalr/signalr-concept-serverless-development-config.md) in the SignalR Service concepts documentation.
15
+
Before a client can connect to Azure SignalR Service, it must retrieve the service endpoint URL and a valid access token. The *SignalRConnectionInfo* input binding produces the SignalR Service endpoint URL and a valid token that are used to connect to the service. The token is time-limited and can be used to authenticate a specific user to a connection. Therefore, you shouldn't cache the token or share it between clients. Usually you use *SignalRConnectionInfo* with HTTP trigger for clients to retrieve the connection information.
18
16
17
+
For more information on how to use this binding to create a "negotiate" function that is compatible with a SignalR client SDK, see [Azure Functions development and configuration with Azure SignalR Service](../azure-signalr/signalr-concept-serverless-development-config.md).
19
18
For information on setup and configuration details, see the [overview](functions-bindings-signalr-service.md).
20
19
21
20
## Example
@@ -40,7 +39,7 @@ public static SignalRConnectionInfo Negotiate(
40
39
41
40
# [Isolated process](#tab/isolated-process)
42
41
43
-
The following example shows a SignalR trigger that reads a message string from one hub using a SignalR trigger and writes it to a second hub using an output binding. The data required to connect to the output binding is obtained as a `MyConnectionInfo` object from an input binding defined using a `SignalRConnectionInfo` attribute.
42
+
The following example shows a [C# function](dotnet-isolated-process-guide.md) that acquires SignalR connection information using the input binding and returns it over HTTP.
@@ -150,15 +149,15 @@ public SignalRConnectionInfo negotiate(
150
149
151
150
### Authenticated tokens
152
151
153
-
When the function is triggered by an authenticated client, you can add a user ID claim to the generated token. You can easily add authentication to a function app using [App Service Authentication](../app-service/overview-authentication-authorization.md).
152
+
When an authenticated client triggers the function, you can add a user ID claim to the generated token. You can easily add authentication to a function app using [App Service Authentication](../app-service/overview-authentication-authorization.md).
154
153
155
154
App Service authentication sets HTTP headers named `x-ms-client-principal-id` and `x-ms-client-principal-name` that contain the authenticated user's client principal ID and name, respectively.
156
155
157
156
::: zone pivot="programming-language-csharp"
158
157
159
158
# [In-process](#tab/in-process)
160
159
161
-
You can set the `UserId` property of the binding to the value from either header using a [binding expression](./functions-bindings-expressions-patterns.md): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
160
+
You can set the `UserId` property of the binding to the value from either header using a [binding expression](#binding-expressions-for-http-trigger): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
162
161
163
162
```cs
164
163
[FunctionName("negotiate")]
@@ -187,7 +186,7 @@ public static string Negotiate([HttpTrigger(AuthorizationLevel.Anonymous)] HttpR
187
186
188
187
# [C# Script](#tab/csharp-script)
189
188
190
-
You can set the `userId` property of the binding to the value from either header using a [binding expression](./functions-bindings-expressions-patterns.md): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
189
+
You can set the `userId` property of the binding to the value from either header using a [binding expression](#binding-expressions-for-http-trigger): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
191
190
192
191
Example function.json:
193
192
@@ -236,7 +235,7 @@ public SignalRConnectionInfo negotiate(
236
235
237
236
::: zone pivot="programming-language-javascript,programming-language-python,programming-language-powershell"
238
237
239
-
You can set the `userId` property of the binding to the value from either header using a [binding expression](./functions-bindings-expressions-patterns.md): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
238
+
You can set the `userId` property of the binding to the value from either header using a [binding expression](#binding-expressions-for-http-trigger): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
You can set the `userId` property of the binding to the value from either header using a [binding expression](./functions-bindings-expressions-patterns.md): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
290
+
You can set the `userId` property of the binding to the value from either header using a [binding expression](#binding-expressions-for-http-trigger): `{headers.x-ms-client-principal-id}` or `{headers.x-ms-client-principal-name}`.
292
291
293
292
```java
294
293
@FunctionName("negotiate")
@@ -318,19 +317,23 @@ The following table explains the properties of the `SignalRConnectionInfo` attri
318
317
319
318
| Attribute property |Description|
320
319
|---------|----------------------|
321
-
**HubName**| This value must be set to the name of the SignalR hub for which the connection information is generated. |
322
-
|**UserId**| Optional: The value of the user identifier claim to be set in the access key token. |
320
+
|**HubName**| Required. The hub name. |
323
321
|**ConnectionStringSetting**| The name of the app setting that contains the SignalR Service connection string, which defaults to `AzureSignalRConnectionString`. |
322
+
|**UserId**| Optional. The user identifier of a SignalR connection. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
323
+
|**IdToken**| Optional. A JWT token whose claims will be added to the user claims. It should be used together with **ClaimTypeList**. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
324
+
|**ClaimTypeList**| Optional. A list of claim types, which filter the claims in **IdToken** . |
324
325
325
326
# [Isolated process](#tab/isolated-process)
326
327
327
328
The following table explains the properties of the `SignalRConnectionInfoInput` attribute:
328
329
329
330
| Attribute property |Description|
330
331
|---------|----------------------|
331
-
**HubName**| This value must be set to the name of the SignalR hub for which the connection information is generated. |
332
-
|**UserId**| Optional: The value of the user identifier claim to be set in the access key token. |
332
+
|**HubName**| Required. The hub name. |
333
333
|**ConnectionStringSetting**| The name of the app setting that contains the SignalR Service connection string, which defaults to `AzureSignalRConnectionString`. |
334
+
|**UserId**| Optional. The user identifier of a SignalR connection. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
335
+
|**IdToken**| Optional. A JWT token whose claims will be added to the user claims. It should be used together with **ClaimTypeList**. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
336
+
|**ClaimTypeList**| Optional. A list of claim types, which filter the claims in **IdToken** . |
334
337
335
338
# [C# Script](#tab/csharp-script)
336
339
@@ -341,25 +344,30 @@ The following table explains the binding configuration properties that you set i
341
344
|**type**| Must be set to `signalRConnectionInfo`.|
342
345
|**direction**| Must be set to `in`.|
343
346
|**name**| Variable name used in function code for connection info object. |
344
-
|**hubName**| This value must be set to the name of the SignalR hub for which the connection information is generated.|
345
-
|**userId**| Optional: The value of the user identifier claim to be set in the access key token. |
347
+
|**hubName**| Required. The hub name. |
346
348
|**connectionStringSetting**| The name of the app setting that contains the SignalR Service connection string, which defaults to `AzureSignalRConnectionString`. |
349
+
|**userId**| Optional. The user identifier of a SignalR connection. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
350
+
|**idToken**| Optional. A JWT token whose claims will be added to the user claims. It should be used together with **claimTypeList**. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
351
+
|**claimTypeList**| Optional. A list of claim types, which filter the claims in **idToken** . |
347
352
348
353
---
349
354
350
355
::: zone-end
351
356
::: zone pivot="programming-language-java"
352
357
358
+
353
359
## Annotations
354
360
355
361
The following table explains the supported settings for the `SignalRConnectionInfoInput` annotation.
356
362
357
363
|Setting | Description|
358
364
|---------|--------|
359
365
|**name**| Variable name used in function code for connection info object. |
360
-
|**hubName**| This value must be set to the name of the SignalR hub for which the connection information is generated.|
361
-
|**userId**| Optional: The value of the user identifier claim to be set in the access key token. |
366
+
|**hubName**| Required. The hub name. |
362
367
|**connectionStringSetting**| The name of the app setting that contains the SignalR Service connection string, which defaults to `AzureSignalRConnectionString`. |
368
+
|**userId**| Optional. The user identifier of a SignalR connection. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
369
+
|**idToken**| Optional. A JWT token whose claims will be added to the user claims. It should be used together with **claimTypeList**. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
370
+
|**claimTypeList**| Optional. A list of claim types, which filter the claims in **idToken** . |
363
371
364
372
::: zone-end
365
373
::: zone pivot="programming-language-javascript,programming-language-powershell,programming-language-python"
@@ -371,13 +379,23 @@ The following table explains the binding configuration properties that you set i
371
379
|---------|--------|
372
380
|**type**| Must be set to `signalRConnectionInfo`.|
373
381
|**direction**| Must be set to `in`.|
374
-
|**name**| Variable name used in function code for connection info object. |
375
-
|**hubName**| This value must be set to the name of the SignalR hub for which the connection information is generated.|
376
-
|**userId**| Optional: The value of the user identifier claim to be set in the access key token. |
382
+
|**hubName**| Required. The hub name. |
377
383
|**connectionStringSetting**| The name of the app setting that contains the SignalR Service connection string, which defaults to `AzureSignalRConnectionString`. |
384
+
|**userId**| Optional. The user identifier of a SignalR connection. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
385
+
|**idToken**| Optional. A JWT token whose claims will be added to the user claims. It should be used together with **claimTypeList**. You can use a [binding expression](#binding-expressions-for-http-trigger) to bind the value to an HTTP request header or query. |
386
+
|**claimTypeList**| Optional. A list of claim types, which filter the claims in **idToken** . |
It's a common scenario that the values of some attributes of SignalR input binding come from HTTP requests. Therefore, we show how to bind values from HTTP requests to SignalR input binding attributes via [binding expression](./functions-bindings-expressions-patterns.md#trigger-metadata).
393
+
394
+
| HTTP metadata type | Binding expression format | Description | Example |
395
+
|---------|--------|---------|--------|
396
+
| HTTP request query |`{query.QUERY_PARAMETER_NAME}`| Binds the value of corresponding query parameter to an attribute |`{query.userName}`|
397
+
| HTTP request header |`{headers.HEADER_NAME}`| Binds the value of a header to an attribute |`{headers.token}`|
398
+
381
399
## Next steps
382
400
383
401
-[Handle messages from SignalR Service (Trigger binding)](./functions-bindings-signalr-service-trigger.md)
0 commit comments