You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

21 lines
751 B

  1. using System;
  2. using System.Threading.Tasks;
  3. using DotNetCore.CAP.Dashboard;
  4. using Microsoft.AspNetCore.Http;
  5. using Microsoft.Extensions.DependencyInjection;
  6. namespace Sample.RabbitMQ.Postgres.DashboardAuth
  7. {
  8. public class HttpContextDashboardFilter : IDashboardAuthorizationFilter
  9. {
  10. public Task<bool> AuthorizeAsync(DashboardContext context)
  11. {
  12. var httpContextAccessor = context.RequestServices.GetRequiredService<IHttpContextAccessor>();
  13. if (httpContextAccessor is null)
  14. throw new ArgumentException("Configure IHttpContextAccessor as a service on Startup");
  15. return Task.FromResult(httpContextAccessor.HttpContext?.User?.Identity?.IsAuthenticated == true);
  16. }
  17. }
  18. }