/// <summary> /// Returns the User's character id. /// </summary> /// <param name="reader"></param> /// <param name="principal">The <see cref="ClaimsPrincipal"/> instance.</param> /// <returns>The User ID claim value. Will throw if the principal doesn't contain the id.</returns> /// <exception cref="ArgumentException">Throws if the provided principal doesn't contain an id.</exception> /// <remarks>The User ID's character id.</remarks> public static int GetCharacterId(this IClaimsPrincipalReader reader, ClaimsPrincipal principal) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (principal == null) { throw new ArgumentNullException(nameof(principal)); } return(reader.GetSubAccountId <int>(principal)); }
/// <summary> /// Returns the User's Sub-Account ID claim value if present otherwise will throw. /// </summary> /// <param name="reader"></param> /// <param name="principal">The <see cref="ClaimsPrincipal"/> instance.</param> /// <returns>The User ID claim value. Will throw if the principal doesn't contain the id.</returns> /// <exception cref="ArgumentException">Throws if the provided principal doesn't contain an id.</exception> /// <remarks>The User ID claim is identified by <see cref="ClaimTypes.NameIdentifier"/>.</remarks> public static TIdentifierType GetSubAccountId <TIdentifierType>(this IClaimsPrincipalReader reader, ClaimsPrincipal principal) where TIdentifierType : unmanaged { try { string id = reader.GetSubAccountId(principal); if (typeof(TIdentifierType) == typeof(string)) { return((TIdentifierType)(object)id); } if (id == default) { return(default);