public override async Task <IList <Claim> > GetClaimsAsync(ApplicationUser <TKey> 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(IUsersContext context) { _usersTable = new UsersTable(context); _usersRolesTable = new UserRolesTable(context); _rolesTable = new RolesTable(context); _usersClaimsTable = new UserClaimsTable(context); _usersLoginsTable = new UserLoginsTable(context); _userTokensTable = new UserTokensTable(context); }
public UserStore(IDbConnectionFactory dbConnectionFactory) { DbConnectionFactory = dbConnectionFactory; UserTable = new UserTable <TUser>(dbConnectionFactory); RoleTable = new RoleTable(dbConnectionFactory); UserRolesTable = new UserRolesTable(dbConnectionFactory); UserClaimsTable = new UserClaimsTable(dbConnectionFactory); UserLoginsTable = new UserLoginsTable(dbConnectionFactory); }
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); }
public UserStore(SqlServerDatabase database) { Database = database; _userTable = new UserTable <T>(database); _userLoginsTable = new UserLoginsTable <T>(database); _roleTable = new RoleTable <ApplicationRole>(database); _userRolesTable = new UserRolesTable <T>(database); _userClaimsTable = new UserClaimsTable(database); }
/// <inheritdoc/> public override async Task AddClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken) { ThrowIfDisposed(); user.ThrowIfNull(nameof(user)); claims.ThrowIfNull(nameof(claims)); UserClaims = UserClaims ?? (await UserClaimsTable.GetClaimsAsync(user.Id)).ToList(); foreach (var claim in claims) { UserClaims.Add(CreateUserClaim(user, claim)); } }
public override async Task ReplaceClaimAsync(ApplicationUser <TKey> user, Claim claim, Claim newClaim, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); 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.ClaimType = newClaim.Type; matchedClaim.ClaimValue = newClaim.Value; } }
/// <inheritdoc/> public override async Task RemoveClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken) { ThrowIfDisposed(); user.ThrowIfNull(nameof(user)); claims.ThrowIfNull(nameof(claims)); UserClaims = 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); } } }
/// <summary> /// Removes a claim froma user /// </summary> /// <param name="user">User to have claim removed</param> /// <param name="claim">Claim to be removed</param> /// <returns></returns> public Task RemoveClaimAsync(TUser user, Claim claim) { if (user == null) { throw new ArgumentNullException("user"); } if (claim == null) { throw new ArgumentNullException("claim"); } UserClaimsTable.Delete(user, claim); return(Task.FromResult <object>(null)); }
/// <summary> /// Inserts a claim to the UserClaimsTable for the given user /// </summary> /// <param name="user">User to have claim added</param> /// <param name="claim">Claim to be added</param> /// <returns></returns> public Task AddClaimAsync(TUser user, Claim claim) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (claim == null) { throw new ArgumentNullException(nameof(claim)); } UserClaimsTable.Insert(claim, user.Id); return(Task.FromResult(0)); }
public UserStore( UsersTable <TKey> usersTable, UserClaimsTable <TKey> userClaimsTable, UserRolesTable <TKey> userRolesTable, UserLoginsTable <TKey> userLoginsTable, UserTokensTable <TKey> userTokensTable, RolesTable <TKey> rolesTable, IdentityErrorDescriber describer ) : base(describer) { UsersTable = usersTable ?? throw new ArgumentException(nameof(usersTable)); UserClaimsTable = userClaimsTable ?? throw new ArgumentException(nameof(userClaimsTable)); UserRolesTable = userRolesTable ?? throw new ArgumentException(nameof(userRolesTable)); UserLoginsTable = userLoginsTable ?? throw new ArgumentException(nameof(userLoginsTable)); UserTokensTable = userTokensTable ?? throw new ArgumentException(nameof(userTokensTable)); RolesTable = rolesTable ?? throw new ArgumentException(nameof(rolesTable)); }
/// <summary> /// Returns all claims for a given user /// </summary> /// <param name="user"></param> /// <returns></returns> public Task <IList <Claim> > GetClaimsAsync(TUser user) { ClaimsIdentity identity = UserClaimsTable.FindByUserId(user.Id); return(Task.FromResult <IList <Claim> >(identity.Claims.ToList())); }