Skip to content

Commit 8596fa4

Browse files
Merge pull request #247870 from Y-Sindo/Y-Sindo-patch-1
Add doc about SignalR input binding attributes
2 parents 98730b9 + d5aef58 commit 8596fa4

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

articles/azure-functions/functions-bindings-signalr-service-input.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ zone_pivot_groups: programming-languages-set-functions-lang-workers
1212

1313
# SignalR Service input binding for Azure Functions
1414

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.
1816

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).
1918
For information on setup and configuration details, see the [overview](functions-bindings-signalr-service.md).
2019

2120
## Example
@@ -40,7 +39,7 @@ public static SignalRConnectionInfo Negotiate(
4039

4140
# [Isolated process](#tab/isolated-process)
4241

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.
4443

4544
:::code language="csharp" source="~/azure-functions-dotnet-worker/samples/Extensions/SignalR/SignalRNegotiationFunctions.cs" id="snippet_negotiate":::
4645

@@ -150,15 +149,15 @@ public SignalRConnectionInfo negotiate(
150149

151150
### Authenticated tokens
152151

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).
154153

155154
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.
156155

157156
::: zone pivot="programming-language-csharp"
158157

159158
# [In-process](#tab/in-process)
160159

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}`.
162161

163162
```cs
164163
[FunctionName("negotiate")]
@@ -187,7 +186,7 @@ public static string Negotiate([HttpTrigger(AuthorizationLevel.Anonymous)] HttpR
187186

188187
# [C# Script](#tab/csharp-script)
189188

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}`.
191190

192191
Example function.json:
193192

@@ -236,7 +235,7 @@ public SignalRConnectionInfo negotiate(
236235

237236
::: zone pivot="programming-language-javascript,programming-language-python,programming-language-powershell"
238237

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}`.
240239

241240
Here's binding data in the *function.json* file:
242241

@@ -288,7 +287,7 @@ def main(req: func.HttpRequest, connectionInfo: str) -> func.HttpResponse:
288287
::: zone-end
289288
::: zone pivot="programming-language-java"
290289

291-
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}`.
292291

293292
```java
294293
@FunctionName("negotiate")
@@ -318,19 +317,23 @@ The following table explains the properties of the `SignalRConnectionInfo` attri
318317

319318
| Attribute property |Description|
320319
|---------|----------------------|
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. |
323321
|**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** . |
324325

325326
# [Isolated process](#tab/isolated-process)
326327

327328
The following table explains the properties of the `SignalRConnectionInfoInput` attribute:
328329

329330
| Attribute property |Description|
330331
|---------|----------------------|
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. |
333333
|**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** . |
334337

335338
# [C# Script](#tab/csharp-script)
336339

@@ -341,25 +344,30 @@ The following table explains the binding configuration properties that you set i
341344
|**type**| Must be set to `signalRConnectionInfo`.|
342345
|**direction**| Must be set to `in`.|
343346
|**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. |
346348
|**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** . |
347352

348353
---
349354

350355
::: zone-end
351356
::: zone pivot="programming-language-java"
352357

358+
353359
## Annotations
354360

355361
The following table explains the supported settings for the `SignalRConnectionInfoInput` annotation.
356362

357363
|Setting | Description|
358364
|---------|--------|
359365
|**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. |
362367
|**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** . |
363371

364372
::: zone-end
365373
::: 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
371379
|---------|--------|
372380
|**type**| Must be set to `signalRConnectionInfo`.|
373381
|**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. |
377383
|**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** . |
378387

379388
::: zone-end
380389

390+
### Binding expressions for HTTP trigger
391+
<a name="binding-expressions-for-http-trigger"></a>
392+
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+
381399
## Next steps
382400

383401
- [Handle messages from SignalR Service (Trigger binding)](./functions-bindings-signalr-service-trigger.md)

0 commit comments

Comments
 (0)