using System.Security.Claims; using eSuite.Core.Miscellaneous; namespace eSuite.API.Utilities; /// /// These methods are used to help make working with authenticated users easier /// internal static class ClaimsPrincipalExtensions { /// /// This gets the e-mail address of the current user. /// /// /// email address from the JWT Token public static string Email(this ClaimsPrincipal user) { return user.FindFirst(ClaimTypes.Email)?.Value!; } /// /// Gets the Internal DB user Id of the current user. /// /// /// public static long Id(this ClaimsPrincipal user) { return long.Parse(user.FindFirst(ClaimTypes.PrimarySid)?.Value!); } public static GeneralIdRef GeneralIdRef(this ClaimsPrincipal user) { return new GeneralIdRef { Id = user.Id() }; } /// /// Gets the Display name of the user as the time the Token was generated. /// /// /// public static string DisplayName(this ClaimsPrincipal user) { return user.FindFirst(ClaimTypes.Name)?.Value!; } }