예제 #1
0
        public async Task <GroupMembership> RemoveUserFromGroup(GroupMembership groupMembership)
        {
            var membership = _db.GroupMemberships.FirstOrDefault(x => x.UserId == groupMembership.UserId && x.GroupId == groupMembership.GroupId);

            if (membership != null)
            {
                _db.Remove(membership);
                await _db.SaveChangesAsync();
            }

            return(groupMembership);
        }
예제 #2
0
        public async ValueTask ValidateAsync(TokenValidatedContext context)
        {
            var claimsIdentity = context.Principal.Identity as ClaimsIdentity;

            if (claimsIdentity?.Claims is null || !claimsIdentity.Claims.Any())
            {
                context.Fail("This is not our issued token.");
                return;
            }

            var jtiString = claimsIdentity.FindFirst(JwtRegisteredClaimNames.Jti)?.Value;

            if (jtiString is null || !Guid.TryParse(jtiString, out var jti))
            {
                context.Fail("This is not our issued token.");
                return;
            }

            var token = await _jwtIdentityDb.AccessTokens.FirstOrDefaultAsync(t => t.Id == jti);

            if (token is null || token.ExpiresTime < DateTime.Now)
            {
                if (token.ExpiresTime < DateTime.Now)
                {
                    _jwtIdentityDb.Remove(token);
                    await _jwtIdentityDb.SaveChangesAsync();
                }
                context.Fail("Token is not valid");
            }

            token.LastLoginTime      = DateTime.Now;
            token.LastLoginIp        = _context.Connection.RemoteIpAddress.ToString();
            token.LastLoginUserAgent = _context.Request.Headers["User-Agent"][0];
            _jwtIdentityDb.Update(token);
            await _jwtIdentityDb.SaveChangesAsync();

            context.Success();
        }
예제 #3
0
        public async Task <bool> DeleteAsync(string id)
        {
            var entity = await _dbContext.Permissions.FirstOrDefaultAsync(x => x.Id == id);

            if (entity == null)
            {
                throw new ArgumentException("Permission not exists");
            }

            _dbContext.Remove(entity);
            await _dbContext.SaveChangesAsync();

            return(true);
        }
예제 #4
0
        public async Task <IdentityResult> DeleteAsync(string token, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            RefreshToken refreshToken = await FindByTokenAsync(token, cancellationToken);

            _context.Remove(refreshToken);
            try
            {
                await _context.SaveChangesAsync(cancellationToken);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()));
            }
            return(IdentityResult.Success);
        }
예제 #5
0
        public async Task <bool> DeleteAsync(string id)
        {
            var entity = await _dbContext.Roles.FirstOrDefaultAsync(x => x.Id == id);

            if (entity == null)
            {
                throw new ArgumentException("Role not exists");
            }

            if (entity.Name == "admin" || entity.Name == "cerberus-admin" || entity.Name == "tenant-admin")
            {
                throw new ApplicationException("Access dined");
            }

            _dbContext.Remove(entity);
            await _dbContext.SaveChangesAsync();

            return(true);
        }
예제 #6
0
파일: RoleStore.cs 프로젝트: legimenes/loja
 public async Task <IdentityResult> DeleteAsync(Role role, CancellationToken cancellationToken = default(CancellationToken))
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     if (role == null)
     {
         throw new ArgumentNullException(nameof(role));
     }
     _context.Remove(role);
     try
     {
         await _context.SaveChangesAsync(cancellationToken);
     }
     catch (DbUpdateConcurrencyException)
     {
         return(IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()));
     }
     return(IdentityResult.Success);
 }