/// <inheritdoc/> public override async Task <IList <Claim> > GetClaimsAsync(TUser user, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); user.ThrowIfNull(nameof(user)); var userClaims = await UserClaimsTable.GetClaimsAsync(user.Id); return(userClaims.Select(x => new Claim(x.ClaimType, x.ClaimValue)).ToList()); }
public UserStore(IDatabaseConnectionFactory databaseConnectionFactory) { _usersTable = new UsersTable(databaseConnectionFactory); _usersRolesTable = new UserRolesTable(databaseConnectionFactory); _rolesTable = new RolesTable(databaseConnectionFactory); _usersClaimsTable = new UserClaimsTable(databaseConnectionFactory); _usersLoginsTable = new UserLoginsTable(databaseConnectionFactory); _userTokensTable = new UserTokensTable(databaseConnectionFactory); }
/// <inheritdoc/> public override async Task AddClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken) { ThrowIfDisposed(); user.ThrowIfNull(nameof(user)); claims.ThrowIfNull(nameof(claims)); UserClaims ??= (await UserClaimsTable.GetClaimsAsync(user.Id)).ToList(); foreach (var claim in claims) { UserClaims.Add(CreateUserClaim(user, claim)); } }
/// <inheritdoc/> public override async Task RemoveClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken) { ThrowIfDisposed(); user.ThrowIfNull(nameof(user)); claims.ThrowIfNull(nameof(claims)); UserClaims ??= (await UserClaimsTable.GetClaimsAsync(user.Id)).ToList(); foreach (var claim in claims) { var matchedClaims = UserClaims.Where(x => x.UserId.Equals(user.Id) && x.ClaimType == claim.Type && x.ClaimValue == claim.Value); foreach (var matchedClaim in matchedClaims) { UserClaims.Remove(matchedClaim); } } }
/// <inheritdoc/> public override async Task ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ThrowIfDisposed(); user.ThrowIfNull(nameof(user)); claim.ThrowIfNull(nameof(claim)); newClaim.ThrowIfNull(nameof(newClaim)); UserClaims ??= (await UserClaimsTable.GetClaimsAsync(user.Id)).ToList(); var matchedClaims = UserClaims.Where(x => x.UserId.Equals(user.Id) && x.ClaimType == claim.Type && x.ClaimValue == claim.Value); foreach (var matchedClaim in matchedClaims) { matchedClaim.ClaimValue = newClaim.Value; matchedClaim.ClaimType = newClaim.Type; } }