Skip to content

Commit 35fe5b5

Browse files
authored
Merge pull request MicrosoftDocs#34550 from Gimly/patch-3
Corrects the group management samples for C#
2 parents faaf43a + 7d5c89d commit 35fe5b5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,15 @@ The following example adds a user to a group.
276276
[FunctionName("addToGroup")]
277277
public static Task AddToGroup(
278278
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequest req,
279-
string userId,
279+
ClaimsPrincipal claimsPrincipal,
280280
[SignalR(HubName = "chat")]
281281
IAsyncCollector<SignalRGroupAction> signalRGroupActions)
282282
{
283+
var userIdClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier);
283284
return signalRGroupActions.AddAsync(
284285
new SignalRGroupAction
285286
{
286-
UserId = userId,
287+
UserId = userIdClaim.Value,
287288
GroupName = "myGroup",
288289
Action = GroupAction.Add
289290
});
@@ -298,20 +299,24 @@ The following example removes a user from a group.
298299
[FunctionName("removeFromGroup")]
299300
public static Task RemoveFromGroup(
300301
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]HttpRequest req,
301-
string userId,
302+
ClaimsPrincipal claimsPrincipal,
302303
[SignalR(HubName = "chat")]
303304
IAsyncCollector<SignalRGroupAction> signalRGroupActions)
304305
{
306+
var userIdClaim = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier);
305307
return signalRGroupActions.AddAsync(
306308
new SignalRGroupAction
307309
{
308-
UserId = userId,
310+
UserId = userIdClaim.Value,
309311
GroupName = "myGroup",
310312
Action = GroupAction.Remove
311313
});
312314
}
313315
```
314316

317+
> [!NOTE]
318+
> In order to get the `ClaimsPrincipal` correctly bound, you must have configured the authentication settings in Azure Functions.
319+
315320
### 2.x JavaScript send message output examples
316321

317322
#### Broadcast to all clients

0 commit comments

Comments
 (0)