本文整理汇总了C#中IAuthenticationManager.AuthenticateAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthenticationManager.AuthenticateAsync方法的具体用法?C# IAuthenticationManager.AuthenticateAsync怎么用?C# IAuthenticationManager.AuthenticateAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAuthenticationManager
的用法示例。
在下文中一共展示了IAuthenticationManager.AuthenticateAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAuthenticationResult
public async Task<ExternalAuthenticationResult> GetAuthenticationResult(IAuthenticationManager authenticationManager)
{
var authResult = await authenticationManager.AuthenticateAsync(ExternalCookieName);
if (authResult == null)
return null;
if (!authResult.Identity.IsAuthenticated)
return null;
var externalIdentity = authResult.Identity;
var providerKeyClaim = externalIdentity.FindFirst(ClaimTypes.NameIdentifier);
var issuer = providerKeyClaim.Issuer;
var providerKey = providerKeyClaim.Value;
var name = externalIdentity.FindFirstValue(ClaimTypes.Name);
var email = externalIdentity.FindFirstValue(ClaimTypes.Email);
if (String.IsNullOrEmpty(issuer))
throw new NullReferenceException("The identity claims contain no issuer.");
if (String.IsNullOrEmpty(providerKey))
throw new NullReferenceException("The identity claims contain no provider key");
var result = new ExternalAuthenticationResult
{
Issuer = issuer,
ProviderKey = providerKey,
Name = name,
Email = email
};
return result;
}
示例2: TwoFactorBrowserRememberedAsync
private static async Task<bool> TwoFactorBrowserRememberedAsync(IAuthenticationManager manager, long userId)
{
if (manager == null)
{
throw new ArgumentNullException("manager");
}
AuthenticateResult authenticateResult = await manager
.AuthenticateAsync("TwoFactorRememberBrowser");
return authenticateResult != null && authenticateResult.Identity != null && authenticateResult.Identity.GetUserId<long>() == userId;
}