Rename folder from Shogi.Sockets to Shogi.Api

This commit is contained in:
2022-11-09 09:11:25 -06:00
parent 3257b420e9
commit a1f996e508
41 changed files with 6 additions and 6 deletions

View File

@@ -0,0 +1,30 @@
using System.Security.Claims;
namespace Shogi.Api.Extensions;
public static class Extensions
{
private static readonly string MsalUsernameClaim = "preferred_username";
public static string? GetGuestUserId(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? GetMicrosoftUserId(this ClaimsPrincipal self)
{
return self.Claims.FirstOrDefault(c => c.Type == MsalUsernameClaim)?.Value;
}
public static string? GetShogiUserId(this ClaimsPrincipal self) => self.IsMicrosoft() ? self.GetMicrosoftUserId() : self.GetGuestUserId();
}