public void TestChallengAnswerRequest() { var ansr = new DnsChallengeAnswer { KeyAuthorization = "TestKeyAuthz", }; var requ = ChallengeAnswerRequest.CreateRequest(ansr); var json = JsonConvert.SerializeObject(requ, Formatting.None); var dict = JsonConvert.DeserializeObject <Dictionary <string, object> >(json); Assert.AreEqual(requ.Resource, dict[nameof(requ.Resource)]); Assert.AreEqual(ansr.KeyAuthorization, dict[nameof(ansr.KeyAuthorization)]); }
public AuthorizeChallenge SubmitChallengeAnswer(AuthorizationState authzState, string type, bool useRootUrl = false) { AssertInit(); AssertRegistration(); var authzChallenge = authzState.Challenges.FirstOrDefault(x => x.Type == type); if (authzChallenge == null) { throw new ArgumentException("no challenge found matching requested type"); } if (authzChallenge.Challenge == null) { throw new InvalidOperationException("challenge has not been decoded"); } if (authzChallenge.Challenge.Answer == null) { throw new InvalidOperationException("challenge answer has not been generated"); } var requUri = new Uri(authzChallenge.Uri); if (useRootUrl) { requUri = new Uri(RootUrl, requUri.PathAndQuery); } var requ = ChallengeAnswerRequest.CreateRequest(authzChallenge.Challenge.Answer); var resp = RequestHttpPost(requUri, requ); if (resp.IsError) { throw new AcmeWebException(resp.Error as WebException, "Unexpected error", resp); } authzChallenge.SubmitResponse = resp; authzChallenge.SubmitDate = DateTime.Now; return(authzChallenge); }