本文整理汇总了C#中System.Security.Claims.ClaimsPrincipal.FindFirstValue方法的典型用法代码示例。如果您正苦于以下问题:C# ClaimsPrincipal.FindFirstValue方法的具体用法?C# ClaimsPrincipal.FindFirstValue怎么用?C# ClaimsPrincipal.FindFirstValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Claims.ClaimsPrincipal
的用法示例。
在下文中一共展示了ClaimsPrincipal.FindFirstValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefaultUser
/// <summary>
/// Initializes a new instance of the <see cref="DefaultUser"/> class.
/// </summary>
/// <param name="principal">The principal.</param>
private DefaultUser(ClaimsPrincipal principal) {
if (principal == null) {
throw new ArgumentNullException(nameof(principal));
}
_isFromDeserialize = false;
_principal = principal;
if (principal.FindFirstValue(JwtClaimTypes.Subject) == null) {
IsAuthenticated = false;
Id = 0;
}
else {
IsAuthenticated = principal.Identities.Any(i => i.IsAuthenticated);
Id = int.Parse(principal.FindFirstValue(JwtClaimTypes.Subject));
UserName = principal.FindFirstValue(JwtClaimTypes.Name);
}
}
示例2: BuildCacheKey
/// <summary>
/// Builds the cache key to use for this item in the distributed cache.
/// </summary>
/// <param name="claimsPrincipal">A <see cref="System.Security.Claims.ClaimsPrincipal"/> for the signed in user</param>
/// <returns>Cache key for this item.</returns>
private static string BuildCacheKey(ClaimsPrincipal claimsPrincipal)
{
Guard.ArgumentNotNull(claimsPrincipal, nameof(claimsPrincipal));
string clientId = claimsPrincipal.FindFirstValue("aud", true);
return string.Format(
"UserId:{0}::ClientId:{1}",
claimsPrincipal.GetObjectIdentifierValue(),
clientId);
}
开发者ID:Azure-Samples,项目名称:guidance-identity-management-for-multitenant-apps,代码行数:15,代码来源:DistributedTokenCache.cs
示例3: ValidateSecurityStamp
private async Task<ClaimsPrincipal> ValidateSecurityStamp(ClaimsPrincipal principal, string userId) {
Guid userGuid;
if (Guid.TryParse(userId, out userGuid)) {
ClaimsPrincipal freshPrincipal = await Query.Execute(new ClaimsPrincipalByUserId(userGuid));
var freshStamp = freshPrincipal.FindFirstValue(Options.ClaimsIdentity.SecurityStampClaimType);
var currentStamp = principal.FindFirstValue(Options.ClaimsIdentity.SecurityStampClaimType);
if (freshStamp == currentStamp) {
return freshPrincipal;
}
}
return null;
}
示例4: ValidateSecurityStampAsync
public Task<bool> ValidateSecurityStampAsync(User user, ClaimsPrincipal principal)
{
if(user != null && UserManager.SupportsUserSecurityStamp)
{
var securityStamp = principal.FindFirstValue(IdentityOptions.ClaimsIdentity.SecurityStampClaimType);
if(securityStamp == user.SecurityStamp)
{
return Task.FromResult(true);
}
}
return Task.FromResult(false);
}