本文整理汇总了C#中System.Security.Claims.ClaimsIdentity.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# ClaimsIdentity.FindAll方法的具体用法?C# ClaimsIdentity.FindAll怎么用?C# ClaimsIdentity.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Claims.ClaimsIdentity
的用法示例。
在下文中一共展示了ClaimsIdentity.FindAll方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetGroups
public static async Task<List<string>> GetGroups(ClaimsIdentity claimsId)
{
if (claimsId.FindFirst("_claim_names") != null
&& (Json.Decode(claimsId.FindFirst("_claim_names").Value)).groups != null)
return await GetGroupsFromGraphAPI(claimsId);
return claimsId.FindAll("groups").Select(c => c.Value).ToList();
}
示例2: GetMemberGroups
/// <summary>
/// For access check user's group membership must be determined.
/// This method retrieves user's group membership from Azure AD Graph API if not present in the token.
/// </summary>
/// <param name="claimsIdentity">The <see cref="ClaimsIdenity" /> object that represents the
/// claims-based identity of the currently signed in user and contains thier claims.</param>
/// <returns>A list of ObjectIDs representing the groups that the user is member of.</returns>
public static async Task<List<string>> GetMemberGroups(ClaimsIdentity claimsIdentity)
{
//check for groups overage claim. If present query graph API for group membership
if (claimsIdentity.FindFirst("_claim_names") != null
&& (Json.Decode(claimsIdentity.FindFirst("_claim_names").Value)).groups != null)
return await GetGroupsFromGraphAPI(claimsIdentity);
return claimsIdentity.FindAll("groups").Select(c => c.Value).ToList();
}
示例3: FindUserKey
public static string FindUserKey(ClaimsIdentity claimsIdentity)
{
if (claimsIdentity == null)
{
throw new ArgumentNullException("claimsIdentity");
}
Claim nameIdentifierClaim = claimsIdentity.FindAll(ClaimTypes.NameIdentifier).SingleOrDefault();
if (nameIdentifierClaim == null)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Claim type '{0}' was not found.", ClaimTypes.NameIdentifier));
}
return nameIdentifierClaim.Value;
}
示例4: CreateProperties
public static AuthenticationProperties CreateProperties(ClaimsIdentity identity)
{
var roleClaimValues = identity.FindAll(ClaimTypes.Role).Select(c => c.Value);
var roles = string.Join(",", roleClaimValues);
IDictionary<string, string> data = new Dictionary<string, string>
{
{ "userName", identity.FindFirstValue(ClaimTypes.Name) },
{ "userRoles", roles }
};
return new AuthenticationProperties(data);
}
示例5: FindCaseInsensivity
public void FindCaseInsensivity ()
{
var claim_type = new Claim("TYpe", "value");
var id = new ClaimsIdentity (
new[] { claim_type },
"base_auth_type", "base_name_claim_type", null);
var f1 = id.FindFirst ("tyPe");
Assert.AreEqual ("value", f1.Value, "#1");
var f2 = id.FindAll ("tyPE").First ();
Assert.AreEqual ("value", f2.Value, "#2");
}