19 lines
524 B
C#
19 lines
524 B
C#
using System.Security.Claims;
|
|
|
|
namespace RecNet.Application.Common.Security;
|
|
|
|
public static class ClaimsPrincipalExtensions
|
|
{
|
|
public static Guid GetProfileId(this ClaimsPrincipal user)
|
|
{
|
|
var value =
|
|
user.FindFirst("sub")?.Value ??
|
|
user.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
if (!Guid.TryParse(value, out var profileId))
|
|
throw new UnauthorizedAccessException(
|
|
"Account id claim is missing or invalid.");
|
|
|
|
return profileId;
|
|
}
|
|
} |