Created
August 21, 2016 14:11
-
-
Save brockallen/8a372f14f960161bab3e41b63788ce3e to your computer and use it in GitHub Desktop.
Principal extensions
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 PrincipalExtensions | |
{ | |
public static string GetValue(this ClaimsPrincipal user, string type) | |
{ | |
var claim = user.FindFirst(type); | |
if (claim != null) return claim.Value; | |
return null; | |
} | |
public static string GetValue(this IPrincipal user, string type) | |
{ | |
var cp = user as ClaimsPrincipal; | |
if (cp != null) return cp.GetValue(type); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment