public static ValueTask <ClaimCollection> AuthenticateAsync(
     this LoginAuthenticator loginAuthenticator,
     string loginName,
     string passcode,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(loginAuthenticator.AuthenticateAsync(new LoginRequest(loginName, passcode), cancellationToken));
 }
 public static ValueTask <ClaimCollection> AuthenticateAsync(
     this LoginAuthenticator loginAuthenticator,
     LoginRequest loginRequest,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(loginAuthenticator.AuthenticateAsync(new [] { loginRequest })
            .FirstOrDefaultAsync(cancellationToken));
 }
        public async ValueTask <ClaimsPrincipal> AuthenticateAsync(string name, string passcode, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }
            var loginRequests = name.Split(_separator, StringSplitOptions.RemoveEmptyEntries).Map(loginName => new LoginRequest(loginName, passcode));

            var identities = await _loginAuthenticator.AuthenticateAsync(loginRequests)
                             .Select(claims => new ClaimsIdentity(
                                         claims.Select(claim => new Claim(claim.Type, claim.Value, claim.ValueType, claim.Issuer, claim.OriginalIssuer)),
                                         claims.AuthenticationType,
                                         claims.NameClaimType,
                                         claims.RoleClaimType))
                             .ToListAsync(cancellationToken);

            if (identities.Count > 0)
            {
                _logger.LogDebug("Authenticated successfully ({0} identities).", identities.Count);
                return(new ClaimsPrincipal(identities));
            }
            _logger.LogDebug("Authentication failed (no identities has been returned).");
            return(null);
        }