1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2025-08-21 06:54:07 +02:00
Files
.config
.run
.workdir
Agent
Common
Controller
Docker
Utils
Web
Phantom.Web
Phantom.Web.Bootstrap
Phantom.Web.Components
Phantom.Web.Services
Agents
Authentication
CustomAuthenticationStateProvider.cs
UserInfo.cs
UserLoginManager.cs
UserSessionBrowserStorage.cs
UserSessionManager.cs
UserSessions.cs
Authorization
Events
Instances
Rpc
Users
ApplicationProperties.cs
Navigation.cs
Phantom.Web.Services.csproj
PhantomWebServices.cs
.dockerignore
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
Directory.Build.props
Directory.Build.targets
Dockerfile
LICENSE
Packages.props
PhantomPanel.sln
README.md
global.json
2023-12-05 14:27:55 +01:00

24 lines
856 B
C#

using System.Security.Claims;
using Phantom.Common.Data.Web.Users;
namespace Phantom.Web.Services.Authentication;
public sealed record UserInfo(Guid UserGuid, string Username, PermissionSet Permissions) {
private const string AuthenticationType = "Phantom";
internal ClaimsPrincipal AsClaimsPrincipal {
get {
var identity = new ClaimsIdentity(AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Name, Username));
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, UserGuid.ToString()));
return new ClaimsPrincipal(identity);
}
}
public static Guid? TryGetGuid(ClaimsPrincipal principal) {
return principal.Identity is { IsAuthenticated: true, AuthenticationType: AuthenticationType } && principal.FindFirstValue(ClaimTypes.NameIdentifier) is {} guidStr && Guid.TryParse(guidStr, out var guid) ? guid : null;
}
}