30 lines
765 B
C#
30 lines
765 B
C#
using System.Security.Claims;
|
|
|
|
namespace Gameboard.ShogiUI.Sockets.Extensions
|
|
{
|
|
public static class Extensions
|
|
{
|
|
private static readonly string MsalUsernameClaim = "preferred_username";
|
|
|
|
public static string? UserId(this ClaimsPrincipal self)
|
|
{
|
|
return self.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
|
|
}
|
|
|
|
public static string? DisplayName(this ClaimsPrincipal self)
|
|
{
|
|
return self.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
|
|
}
|
|
|
|
public static bool IsMicrosoft(this ClaimsPrincipal self)
|
|
{
|
|
return self.HasClaim(c => c.Type == MsalUsernameClaim);
|
|
}
|
|
|
|
public static string ChangeFirstCharacterToLowerCase(this string self)
|
|
{
|
|
return char.ToLowerInvariant(self[0]) + self[1..];
|
|
}
|
|
}
|
|
}
|