Refactor runtime bootstrap and ship control flows
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace SpaceGame.Api.Auth.Simulation;
|
||||
|
||||
public sealed class HttpContextPlayerIdentityResolver(IHttpContextAccessor httpContextAccessor) : IPlayerIdentityResolver
|
||||
{
|
||||
public Guid? GetCurrentPlayerId()
|
||||
{
|
||||
var subject = httpContextAccessor.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier)
|
||||
?? httpContextAccessor.HttpContext?.User.FindFirstValue("sub");
|
||||
return Guid.TryParse(subject, out var playerId) ? playerId : null;
|
||||
}
|
||||
|
||||
public Guid GetRequiredPlayerId() =>
|
||||
GetCurrentPlayerId() ?? throw new InvalidOperationException("Authenticated player identity is required.");
|
||||
|
||||
public bool CanAccessGm()
|
||||
{
|
||||
var user = httpContextAccessor.HttpContext?.User;
|
||||
return user?.IsInRole("gm") == true || user?.IsInRole("admin") == true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user