This commit is contained in:
2022-06-22 18:29:19 -05:00
parent 770344422d
commit 02e64daec5
9 changed files with 101 additions and 105 deletions

View File

@@ -1,28 +1,29 @@
using System.Linq;
using System.Security.Claims;
using System.Security.Claims;
namespace Gameboard.ShogiUI.Sockets.Extensions
{
public static class Extensions
{
public static string? UserId(this ClaimsPrincipal self)
{
return self.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
}
public static class Extensions
{
private static readonly string MsalUsernameClaim = "preferred_username";
public static string? DisplayName(this ClaimsPrincipal self)
{
return self.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
}
public static string? UserId(this ClaimsPrincipal self)
{
return self.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
}
public static bool IsGuest(this ClaimsPrincipal self)
{
return self.HasClaim(c => c.Type == ClaimTypes.Role && c.Value == "Guest");
}
public static string? DisplayName(this ClaimsPrincipal self)
{
return self.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
}
public static string ToCamelCase(this string self)
{
return char.ToLowerInvariant(self[0]) + self[1..];
}
}
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..];
}
}
}