Use OID instead of email for microsoft identifier. Fix PlayerCount route. Add created date to user table. Create spectator icon.
30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
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
|
|
|
|
/// <summary>
|
|
/// Get Id from claims after applying shogi-specific claims transformations.
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get display name from claims after applying shogi-specific claims transformations.
|
|
/// </summary>
|
|
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;
|
|
}
|
|
|
|
} |