using Microsoft.Identity.Web;
using System.Security.Claims;
namespace Shogi.Api.Extensions;
public static class ClaimsExtensions
{
// https://learn.microsoft.com/en-us/azure/active-directory/develop/id-tokens#payload-claims
///
/// Get Id from claims after applying shogi-specific claims transformations.
///
public static string GetShogiUserId(this ClaimsPrincipal self)
{
var id = self.GetNameIdentifierId();
if (string.IsNullOrEmpty(id)) throw new InvalidOperationException("Shogi UserId not found in claims.");
return id;
}
///
/// Get display name from claims after applying shogi-specific claims transformations.
///
public static string GetShogiUserDisplayname(this ClaimsPrincipal self)
{
var displayName = self.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
if (string.IsNullOrEmpty(displayName)) throw new InvalidOperationException("Shogi Display name not found in claims.");
return displayName;
}
}