Browse Source

Merge pull request #10508 from abpframework/AbpSignalRHubFilter

Switch to `ClaimsPrincipal` in `HubContext`.
pull/10534/head
Halil İbrahim Kalkan 5 years ago
committed by GitHub
parent
commit
bd3da5831a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpAspNetCoreSignalRModule.cs
  2. 38
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpSignalRHubFilter.cs

5
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpAspNetCoreSignalRModule.cs

@ -32,7 +32,10 @@ namespace Volo.Abp.AspNetCore.SignalR
public override void ConfigureServices(ServiceConfigurationContext context)
{
var routePatterns = new List<string> {"/signalr-hubs"};
var signalRServerBuilder = context.Services.AddSignalR();
var signalRServerBuilder = context.Services.AddSignalR(options =>
{
options.AddFilter<AbpSignalRHubFilter>();
});
context.Services.ExecutePreConfiguredActions(signalRServerBuilder);

38
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpSignalRHubFilter.cs

@ -0,0 +1,38 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Security.Claims;
namespace Volo.Abp.AspNetCore.SignalR
{
public class AbpSignalRHubFilter : IHubFilter
{
public virtual async ValueTask<object> InvokeMethodAsync(HubInvocationContext invocationContext, Func<HubInvocationContext, ValueTask<object>> next)
{
var currentPrincipalAccessor = invocationContext.ServiceProvider.GetRequiredService<ICurrentPrincipalAccessor>();
using (currentPrincipalAccessor.Change(invocationContext.Context.User))
{
return await next(invocationContext);
}
}
public virtual async Task OnConnectedAsync(HubLifetimeContext context, Func<HubLifetimeContext, Task> next)
{
var currentPrincipalAccessor = context.ServiceProvider.GetRequiredService<ICurrentPrincipalAccessor>();
using (currentPrincipalAccessor.Change(context.Context.User))
{
await next(context);
}
}
public virtual async Task OnDisconnectedAsync(HubLifetimeContext context, Exception exception, Func<HubLifetimeContext, Exception, Task> next)
{
var currentPrincipalAccessor = context.ServiceProvider.GetRequiredService<ICurrentPrincipalAccessor>();
using (currentPrincipalAccessor.Change(context.Context.User))
{
await next(context, exception);
}
}
}
}
Loading…
Cancel
Save