private AzureFunctionsPrincipal ParsePortalToken(string portalToken)
{
if (string.IsNullOrEmpty(portalToken))
{
throw new ArgumentException($"{nameof(portalToken)} cannot be null or empty.");
}
var jwt = new JwtSecurityToken(portalToken);
var principalName = jwt.Claims.FirstOrDefault(c => c.Type == Email)?.Value ?? jwt.Claims.FirstOrDefault(c => c.Type == UniqueName)?.Value;
var displayName = jwt.Claims.FirstOrDefault(c => c.Type == Name)?.Value ?? jwt.Claims.FirstOrDefault(c => c.Type == GivenName)?.Value;
return new AzureFunctionsPrincipal(new AzureFunctionsIdentity(principalName ?? displayName));
}