/// <summary> /// Gets claims of the specified cliam type of the specified ClaimsPrincipal. /// </summary> /// <param name="this"></param> /// <param name="authenticationType">If null, then use the default authenticationType.</param> /// <param name="claimType"></param> /// <returns></returns> public static IEnumerable <string> GetClaims(this ClaimsPrincipal @this, string authenticationType, string claimType) { ClaimsIdentity identity; if (authenticationType != null) { identity = @this.Identities.FirstOrDefault(x => x.AuthenticationType == authenticationType); } else { identity = @this.Identity as ClaimsIdentity; } if (identity != null) { return(DawnClaimsIdentity.GetClaims(identity, claimType)); } else { return(new string[0]); } }
/// <summary> /// Gets roles of the specified ClaimsPrincipal. /// </summary> /// <param name="this"></param> /// <param name="authenticationType">If null, then use the default authenticationType.</param> /// <returns></returns> public static string GetName(this ClaimsPrincipal @this, string authenticationType = null) { ClaimsIdentity identity; if (authenticationType != null) { identity = @this.Identities.FirstOrDefault(x => x.AuthenticationType == authenticationType); } else { identity = @this.Identity as ClaimsIdentity; } if (identity != null) { return(DawnClaimsIdentity.GetName(identity)); } else { return(null); } }