mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Shows a connection-lost indicator when the SignalR connection closes.
This commit is contained in:
1 parent
0abf8d4aea
commit
e2c705d822
44 files changed
+1254
-78
No files matched your search
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Enums.Authorization;
|
||||
using Lumina.Presentation.Web.Common.Http;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -13,14 +15,17 @@ namespace Lumina.Presentation.Web.Common.Authorization;
|
||||
public class PermissionAuthorizationHandler : AuthorizationHandler<PermissionRequirement>
|
||||
{
|
||||
private readonly IAuthorizationService _authorizationService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PermissionAuthorizationHandler"/> class.
|
||||
/// </summary>
|
||||
/// <param name="authorizationService">Injected service for authorization checks against the remote API.</param>
|
||||
public PermissionAuthorizationHandler(IAuthorizationService authorizationService)
|
||||
/// <param name="httpContextAccessor">Injected accessor for the current HTTP context.</param>
|
||||
public PermissionAuthorizationHandler(IAuthorizationService authorizationService, IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_authorizationService = authorizationService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,5 +49,13 @@ public class PermissionAuthorizationHandler : AuthorizationHandler<PermissionReq
|
||||
return;
|
||||
}
|
||||
}
|
||||
// The authorization service marks a page navigation when the API could not answer. The page itself is still rendered, with
|
||||
// no permission granted, and it reports the failure to the user; the API remains the enforcement point for every data call.
|
||||
// Endpoint routing passes the Endpoint, not the HttpContext, as the authorization resource, so the current request is read
|
||||
// from the accessor instead. Only an authenticated user is allowed through, because the outage is not a reason to expose a
|
||||
// page to an anonymous visitor.
|
||||
HttpContext? httpContext = _httpContextAccessor.HttpContext;
|
||||
if (httpContext?.User.Identity?.IsAuthenticated == true && httpContext.Items[HttpContextItemKeys.SERVER_UNREACHABLE] is true)
|
||||
authorizationHandlerContext.Succeed(permissionRequirement);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user