@@ -276,14 +276,15 @@ The following example adds a user to a group.
276
276
[FunctionName (" addToGroup" )]
277
277
public static Task AddToGroup (
278
278
[HttpTrigger (AuthorizationLevel .Anonymous , " post" )]HttpRequest req ,
279
- string userId ,
279
+ ClaimsPrincipal claimsPrincipal ,
280
280
[SignalR (HubName = " chat" )]
281
281
IAsyncCollector < SignalRGroupAction > signalRGroupActions )
282
282
{
283
+ var userIdClaim = claimsPrincipal .FindFirst (ClaimTypes .NameIdentifier );
283
284
return signalRGroupActions .AddAsync (
284
285
new SignalRGroupAction
285
286
{
286
- UserId = userId ,
287
+ UserId = userIdClaim . Value ,
287
288
GroupName = " myGroup" ,
288
289
Action = GroupAction .Add
289
290
});
@@ -298,20 +299,24 @@ The following example removes a user from a group.
298
299
[FunctionName (" removeFromGroup" )]
299
300
public static Task RemoveFromGroup (
300
301
[HttpTrigger (AuthorizationLevel .Anonymous , " post" )]HttpRequest req ,
301
- string userId ,
302
+ ClaimsPrincipal claimsPrincipal ,
302
303
[SignalR (HubName = " chat" )]
303
304
IAsyncCollector < SignalRGroupAction > signalRGroupActions )
304
305
{
306
+ var userIdClaim = claimsPrincipal .FindFirst (ClaimTypes .NameIdentifier );
305
307
return signalRGroupActions .AddAsync (
306
308
new SignalRGroupAction
307
309
{
308
- UserId = userId ,
310
+ UserId = userIdClaim . Value ,
309
311
GroupName = " myGroup" ,
310
312
Action = GroupAction .Remove
311
313
});
312
314
}
313
315
```
314
316
317
+ > [ !NOTE]
318
+ > In order to get the ` ClaimsPrincipal ` correctly bound, you must have configured the authentication settings in Azure Functions.
319
+
315
320
### 2.x JavaScript send message output examples
316
321
317
322
#### Broadcast to all clients
0 commit comments