-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSignalRAuthorizationFilter.cs
More file actions
37 lines (31 loc) · 1.18 KB
/
SignalRAuthorizationFilter.cs
File metadata and controls
37 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Orleans.Runtime;
using ManagedCode.Orleans.Identity.Core.Constants;
namespace ManagedCode.Orleans.Identity.Client.Middlewares;
public class SignalRAuthorizationFilter : IHubFilter
{
public async ValueTask<object?> InvokeMethodAsync(
HubInvocationContext invocationContext,
Func<HubInvocationContext, ValueTask<object?>> next)
{
if (invocationContext.Context.User?.Identity?.IsAuthenticated == true)
{
RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, invocationContext.Context.User);
}
return await next(invocationContext);
}
public Task OnConnectedAsync(HubLifetimeContext context, Func<HubLifetimeContext, Task> next)
{
if (context.Context.User?.Identity?.IsAuthenticated == true)
{
RequestContext.Set(OrleansIdentityConstants.USER_CLAIMS, context.Context.User);
}
return next(context);
}
public Task OnDisconnectedAsync(HubLifetimeContext context, Exception? exception, Func<HubLifetimeContext, Exception?, Task> next)
{
return next(context, exception);
}
}