Created
May 24, 2018 15:56
-
-
Save IanWold/5a07e0df62ac2db69f68b3215d7c4e35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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