コード例 #1
0
        public async Task <RegistrationResponse> RegisterAsync(string termsOfServiceUri, string[] contact)
        {
            await EnsureDirectoryAsync().ConfigureAwait(false);

            Info("trying to create new registration");

            var request = new NewRegistrationRequest {
                Contact   = contact,
                Agreement = termsOfServiceUri ?? directory.Meta.TermsOfService
            };

            try
            {
                var registration = await PostAsync <RegistrationResponse>(directory.NewRegistration, request).ConfigureAwait(false);

                Info($"new registration created: {registration.Location}");

                return(registration);
            }
            catch (AcmeException ex) when((int)ex.Response.StatusCode == 409)  // Conflict
            {
                var location = ex.Response.Headers.Location.ToString();

                Info($"using existing registration: {location}");
                var response = await PostAsync <RegistrationResponse>(new Uri(location), new UpdateRegistrationRequest()).ConfigureAwait(false);

                if (string.IsNullOrEmpty(response.Location))
                {
                    response.Location = location;
                }
                return(response);
            }
        }
コード例 #2
0
        public void Can_serialize()
        {
            var request = new NewRegistrationRequest
            {
                Contact = new[] {
                    "mailto:[email protected]",
                    "tel:+12025551212"
                },
                Key = new Jwk {
                    Algorithm = "none"
                },
                Agreement      = "https://example.com/acme/terms",
                Authorizations = "https://example.com/acme/reg/1/authz",
                Certificates   = "https://example.com/acme/reg/1/cert",
            };

            var json = JsonConvert.SerializeObject(request, Formatting.Indented, new JsonSerializerSettings {
                DefaultValueHandling = DefaultValueHandling.Ignore
            });


            Assert.Equal(@"{
  ""resource"": ""new-reg"",
  ""jwk"": {
    ""alg"": ""none""
  },
  ""contact"": [
    ""mailto:[email protected]"",
    ""tel:+12025551212""
  ],
  ""agreement"": ""https://example.com/acme/terms"",
  ""authorizations"": ""https://example.com/acme/reg/1/authz"",
  ""certificates"": ""https://example.com/acme/reg/1/cert""
}".Replace("\r\n", "\n"), json.Replace("\r\n", "\n"));
        }
コード例 #3
0
        public async Task <RegistrationResponse> RegisterAsync(NewRegistrationRequest request)
        {
            await EnsureDirectoryAsync().ConfigureAwait(false);

            if (request.Agreement == null)
            {
                request.Agreement = directory.Meta.TermsOfService;
            }

            try
            {
                var registration = await PostAsync <RegistrationResponse>(
                    uri : directory.NewRegistration,
                    message : request
                    ).ConfigureAwait(false);

                Info($"new registration created: {registration.Location}");

                return(registration);
            }
            catch (AcmeException ex) when(ex.Response.StatusCode == HttpStatusCode.Conflict)
            {
                var location = ex.Response.Headers.Location.ToString();

                Info($"using existing registration: {location}");

                var response = await PostAsync <RegistrationResponse>(
                    uri : new Uri(location),
                    message : new UpdateRegistrationRequest()
                    ).ConfigureAwait(false);

                if (string.IsNullOrEmpty(response.Location))
                {
                    response.Location = location;
                }

                return(response);
            }
        }
コード例 #4
0
            public async Task <RegistrationResponse> RegisterAsync(NewRegistrationRequest request, CancellationToken token = default(CancellationToken))
            {
                await EnsureDirectoryAsync(token).ConfigureAwait(false);

                if (request.Agreement == null)
                {
                    request.Agreement = _directory.Meta.TermsOfService;
                }

                try
                {
                    var registration = await PostAsync <RegistrationResponse>(
                        _directory.NewRegistration,
                        request,
                        token
                        ).ConfigureAwait(false);

                    return(registration);
                }
                catch (AcmeException ex) when(ex.Response.StatusCode == HttpStatusCode.Conflict)
                {
                    var location = ex.Response.Headers.Location.ToString();

                    var response = await PostAsync <RegistrationResponse>(
                        new Uri(location),
                        new UpdateRegistrationRequest(),
                        token
                        ).ConfigureAwait(false);

                    if (string.IsNullOrEmpty(response.Location))
                    {
                        response.Location = location;
                    }

                    return(response);
                }
            }