Ejemplo n.º 1
0
        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 Let's Encrypt 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);
        }