Exemplo n.º 1
0
        private async Task <AccountModel> CreateAccount(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (_client == null || _acmeAccountKey == null)
            {
                throw new InvalidOperationException();
            }

            var tosUri = await _client.GetTermsOfServiceAsync();

            _tosChecker.EnsureTermsAreAccepted(tosUri);

            var options = _options.Value;

            _logger.LogInformation("Creating new account for {email}", options.EmailAddress);
            var accountId = await _client.CreateAccountAsync(options.EmailAddress);

            var accountModel = new AccountModel
            {
                Id             = accountId,
                EmailAddresses = new[] { options.EmailAddress },
                PrivateKey     = _acmeAccountKey.ToDer(),
            };

            await _accountRepository.SaveAccountAsync(accountModel, cancellationToken);

            return(accountModel);
        }
        private async Task <AccountModel> CreateAccount(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            Debug.Assert(_context != null);

            var tosUri = await _context.TermsOfService();

            _tosChecker.EnsureTermsAreAccepted(tosUri);

            var options = _options.Value;

            _logger.LogInformation("Creating new account for {email}", options.EmailAddress);
            _accountContext = await _context.NewAccount(options.EmailAddress, termsOfServiceAgreed : true);

            _logger.LogAcmeAction("NewRegistration");

            if (!int.TryParse(_accountContext.Location.Segments.Last(), out var accountId))
            {
                accountId = 0;
            }

            var account = new AccountModel
            {
                Id             = accountId,
                EmailAddresses = new[] { options.EmailAddress },
                PrivateKey     = _context !.AccountKey.ToDer(),
            };

            await _accountRepository.SaveAccountAsync(account, cancellationToken);

            return(account);
        }