private async Task <Claim[]> GetUserLoginClaims(AuthenticatedUser user, bool wasMultiFactorAuthenticated) { await _contentObjectService.Refresh(); var claims = new List <Claim>(); if (_contentObjectService.LoginDiscontinuationConfiguration.IsLoginDiscontinued(user)) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.DiscontinuedLogin); } if (user.User.HasPasswordCredential()) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.PasswordLogin); } if (user.User.HasExternalCredential()) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.ExternalLogin); } if (user.User.EnableMultiFactorAuthentication) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.EnabledMultiFactorAuthentication); } if (wasMultiFactorAuthenticated) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.WasMultiFactorAuthenticated); } ClaimsExtensions.AddExternalLoginCredentialTypeClaim(claims, user.CredentialUsed.Type); return(claims.ToArray()); }
private static Mock <ClaimsIdentity> BuildClaimsIdentity(string authType, bool authenticated, bool hasDiscontinuedLoginClaim) { var mockIdentity = new Mock <ClaimsIdentity>(); var claims = new List <Claim>(); if (hasDiscontinuedLoginClaim) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.DiscontinuedLogin); } mockIdentity.SetupGet(i => i.Claims).Returns(claims.ToArray()); mockIdentity.SetupGet(i => i.IsAuthenticated).Returns(authenticated); mockIdentity.SetupGet(i => i.AuthenticationType).Returns(authType); return(mockIdentity); }
private async Task <Claim[]> GetDiscontinuedLoginClaims(AuthenticatedUser user) { await _contentObjectService.Refresh(); var claims = new List <Claim>(); if (_contentObjectService.LoginDiscontinuationConfiguration.IsLoginDiscontinued(user)) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.DiscontinuedLogin); } if (user.User.HasPasswordCredential()) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.PasswordLogin); } if (user.User.HasExternalCredential()) { ClaimsExtensions.AddBooleanClaim(claims, NuGetClaims.ExternalLogin); } return(claims.ToArray()); }