public async Task <ActionResult <Protocol.HttpModel.Order> > CreateOrder(AcmePayload <CreateOrderRequest> payload)
        {
            var account = await _accountService.FromRequestAsync(HttpContext.RequestAborted);

            var orderRequest = payload.Value;

            if (orderRequest.Identifiers?.Any() != true)
            {
                throw new MalformedRequestException("No identifiers submitted");
            }

            foreach (var i in orderRequest.Identifiers)
            {
                if (string.IsNullOrWhiteSpace(i.Type) || string.IsNullOrWhiteSpace(i.Value))
                {
                    throw new MalformedRequestException($"Malformed identifier: (Type: {i.Type}, Value: {i.Value})");
                }
            }

            var identifiers = orderRequest.Identifiers.Select(x =>
                                                              new Protocol.Model.Identifier(x.Type !, x.Value !)
                                                              );

            var order = await _orderService.CreateOrderAsync(
                account, identifiers,
                orderRequest.NotBefore, orderRequest.NotAfter,
                HttpContext.RequestAborted);

            GetOrderUrls(order, out var authorizationUrls, out var finalizeUrl, out var certificateUrl);
            var orderResponse = new Protocol.HttpModel.Order(order, authorizationUrls, finalizeUrl, certificateUrl);

            var orderUrl = Url.RouteUrl("GetOrder", new { orderId = order.OrderId }, HttpContext.GetProtocol());

            return(new CreatedResult(orderUrl, orderResponse));
        }
        public Task BindModelAsync(ModelBindingContext bindingContext)
        {
            if (bindingContext is null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            var acmePayload = new AcmePayload <TPayload>(_requestProvider.GetPayload <TPayload>());

            bindingContext.Result = ModelBindingResult.Success(acmePayload);

            return(Task.CompletedTask);
        }
        public async Task <ActionResult <Protocol.HttpModel.Order> > FinalizeOrder(string orderId, AcmePayload <FinalizeOrderRequest> payload)
        {
            var account = await _accountService.FromRequestAsync(HttpContext.RequestAborted);

            var order = await _orderService.ProcessCsr(account, orderId, payload.Value.Csr, HttpContext.RequestAborted);

            GetOrderUrls(order, out var authorizationUrls, out var finalizeUrl, out var certificateUrl);

            var orderResponse = new Protocol.HttpModel.Order(order, authorizationUrls, finalizeUrl, certificateUrl);

            return(orderResponse);
        }
Example #4
0
 public Task <ActionResult <Protocol.HttpModel.OrdersList> > GetOrdersList(string accountId, AcmePayload <object> payload)
 {
     throw new NotImplementedException();
 }
Example #5
0
 private Task <ActionResult <Protocol.HttpModel.Account> > FindAccountAsync(AcmePayload <CreateOrGetAccount> payload)
 {
     throw new NotImplementedException();
 }
Example #6
0
        private async Task <ActionResult <Protocol.HttpModel.Account> > CreateAccountAsync(AcmeHeader header, AcmePayload <CreateOrGetAccount> payload)
        {
            if (payload == null)
            {
                throw new MalformedRequestException("Payload was empty or could not be read.");
            }

            var account = await _accountService.CreateAccountAsync(
                header.Jwk !, //Post requests are validated, JWK exists.
                payload.Value.Contact,
                payload.Value.TermsOfServiceAgreed,
                HttpContext.RequestAborted);

            var ordersUrl       = Url.RouteUrl("OrderList", new { accountId = account.AccountId }, "https");
            var accountResponse = new Protocol.HttpModel.Account(account, ordersUrl);

            var accountUrl = Url.RouteUrl("Account", new { accountId = account.AccountId }, "https");

            return(new CreatedResult(accountUrl, accountResponse));
        }
Example #7
0
        public async Task <ActionResult <Protocol.HttpModel.Account> > CreateOrGetAccount(AcmeHeader header, AcmePayload <CreateOrGetAccount> payload)
        {
            if (payload.Value.OnlyReturnExisting)
            {
                return(await FindAccountAsync(payload));
            }

            return(await CreateAccountAsync(header, payload));
        }