Exemplo n.º 1
0
        public async Task PostSecurityStamp([FromBody] SecretVerificationRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            var result = await _userService.RefreshSecurityStampAsync(user, model.Secret);

            if (result.Succeeded)
            {
                return;
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }

            await Task.Delay(2000);

            throw new BadRequestException(ModelState);
        }
Exemplo n.º 2
0
        public async Task Delete([FromBody] SecretVerificationRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (!await _userService.VerifySecretAsync(user, model.Secret))
            {
                ModelState.AddModelError(string.Empty, "User verification failed.");
                await Task.Delay(2000);
            }
            else
            {
                var result = await _userService.DeleteAsync(user);

                if (result.Succeeded)
                {
                    return;
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            throw new BadRequestException(ModelState);
        }
Exemplo n.º 3
0
        public async Task <ApiKeyResponseModel> ApiKey(string id, [FromBody] SecretVerificationRequestModel model)
        {
            var orgIdGuid = new Guid(id);

            if (!await _currentContext.OrganizationOwner(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);

            if (organization == null)
            {
                throw new NotFoundException();
            }

            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (!await _userService.VerifySecretAsync(user, model.Secret))
            {
                await Task.Delay(2000);

                throw new BadRequestException("MasterPasswordHash", "Invalid password.");
            }
            else
            {
                var response = new ApiKeyResponseModel(organization);
                return(response);
            }
        }
Exemplo n.º 4
0
        public async Task PostPurge([FromBody] SecretVerificationRequestModel model, string organizationId = null)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (!await _userService.VerifySecretAsync(user, model.Secret))
            {
                ModelState.AddModelError(string.Empty, "User verification failed.");
                await Task.Delay(2000);

                throw new BadRequestException(ModelState);
            }

            if (string.IsNullOrWhiteSpace(organizationId))
            {
                await _cipherRepository.DeleteByUserIdAsync(user.Id);
            }
            else
            {
                var orgId = new Guid(organizationId);
                if (!await _currentContext.EditAnyCollection(orgId))
                {
                    throw new NotFoundException();
                }
                await _cipherService.PurgeAsync(orgId);
            }
        }
Exemplo n.º 5
0
        public async Task Delete(string id, [FromBody] SecretVerificationRequestModel model)
        {
            var orgIdGuid = new Guid(id);

            if (!await _currentContext.OrganizationOwner(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);

            if (organization == null)
            {
                throw new NotFoundException();
            }

            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (!await _userService.VerifySecretAsync(user, model.Secret))
            {
                await Task.Delay(2000);

                throw new BadRequestException(string.Empty, "User verification failed.");
            }
            else
            {
                await _organizationService.DeleteAsync(organization);
            }
        }
Exemplo n.º 6
0
        public async Task <TwoFactorAuthenticatorResponseModel> GetAuthenticator([FromBody] SecretVerificationRequestModel model)
        {
            var user = await CheckAsync(model, false);

            var response = new TwoFactorAuthenticatorResponseModel(user);

            return(response);
        }
Exemplo n.º 7
0
        public async Task <CredentialCreateOptions> GetWebAuthnChallenge([FromBody] SecretVerificationRequestModel model)
        {
            var user = await CheckAsync(model, true);

            var reg = await _userService.StartWebAuthnRegistrationAsync(user);

            return(reg);
        }
Exemplo n.º 8
0
        public async Task <TwoFactorWebAuthnResponseModel> GetWebAuthn([FromBody] SecretVerificationRequestModel model)
        {
            var user = await CheckAsync(model, true);

            var response = new TwoFactorWebAuthnResponseModel(user);

            return(response);
        }
Exemplo n.º 9
0
        public async Task <ApiKeyResponseModel> ApiKey([FromBody] SecretVerificationRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (!await _userService.VerifySecretAsync(user, model.Secret))
            {
                await Task.Delay(2000);

                throw new BadRequestException(string.Empty, "User verification failed.");
            }

            return(new ApiKeyResponseModel(user));
        }
Exemplo n.º 10
0
        public async Task PostVerifyPassword([FromBody] SecretVerificationRequestModel model)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (await _userService.CheckPasswordAsync(user, model.MasterPasswordHash))
            {
                return;
            }

            ModelState.AddModelError(nameof(model.MasterPasswordHash), "Invalid password.");
            await Task.Delay(2000);

            throw new BadRequestException(ModelState);
        }
Exemplo n.º 11
0
        private async Task <User> CheckAsync(SecretVerificationRequestModel model, bool premium)
        {
            var user = await _userService.GetUserByPrincipalAsync(User);

            if (user == null)
            {
                throw new UnauthorizedAccessException();
            }

            if (!await _userService.VerifySecretAsync(user, model.Secret))
            {
                await Task.Delay(2000);

                throw new BadRequestException(string.Empty, "User verification failed.");
            }

            if (premium && !(await _userService.CanAccessPremium(user)))
            {
                throw new BadRequestException("Premium status is required.");
            }

            return(user);
        }
Exemplo n.º 12
0
        public async Task <TwoFactorDuoResponseModel> GetOrganizationDuo(string id,
                                                                         [FromBody] SecretVerificationRequestModel model)
        {
            var user = await CheckAsync(model, false);

            var orgIdGuid = new Guid(id);

            if (!await _currentContext.ManagePolicies(orgIdGuid))
            {
                throw new NotFoundException();
            }

            var organization = await _organizationRepository.GetByIdAsync(orgIdGuid);

            if (organization == null)
            {
                throw new NotFoundException();
            }

            var response = new TwoFactorDuoResponseModel(organization);

            return(response);
        }