Skip to content

Instantly share code, notes, and snippets.

@IanWold
Created May 24, 2018 15:56
Show Gist options
  • Save IanWold/5a07e0df62ac2db69f68b3215d7c4e35 to your computer and use it in GitHub Desktop.
Save IanWold/5a07e0df62ac2db69f68b3215d7c4e35 to your computer and use it in GitHub Desktop.
public static class ClaimsExtensions
{
public static string GetClaimValue(this HttpContext context, string type)
{
if (context.User.Claims.FirstOrDefault(c => c.Type == type) is Claim claim)
{
return claim.Value;
}
else throw new ArgumentException(type + " is not found in claims.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment