Skip to content

Instantly share code, notes, and snippets.

@brockallen
Created August 21, 2016 14:11
Show Gist options
  • Save brockallen/8a372f14f960161bab3e41b63788ce3e to your computer and use it in GitHub Desktop.
Save brockallen/8a372f14f960161bab3e41b63788ce3e to your computer and use it in GitHub Desktop.
Principal extensions
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