public static string GeneratePresentationRequest(this PresentationRequestConfiguration configuration) { PresentationRequest_v_1_0 presentationRequest_1_0 = new PresentationRequest_v_1_0() { Version = configuration.Version, Name = configuration.Name }; configuration.RequestedAttributes.ForEach(delegate(RequestedAttribute reqAttribute) { presentationRequest_1_0.RequestedAttributes.Add(Guid.NewGuid().ToString(), reqAttribute); }); configuration.RequestedPredicates.ForEach(delegate(RequestedPredicate reqPredicate) { presentationRequest_1_0.RequestedPredicates.Add(Guid.NewGuid().ToString(), reqPredicate); }); Dictionary <string, PresentationRequest_v_1_0> requestBody = new Dictionary <string, PresentationRequest_v_1_0>() { { "proof_request", presentationRequest_1_0 } }; return(JsonConvert.SerializeObject(requestBody)); }
public static string GeneratePresentationRequest(this PresentationRequestConfiguration configuration) { PresentationRequest_v_1_0 presentationRequest_1_0 = new PresentationRequest_v_1_0() { Version = configuration.Version, Name = configuration.Name // NonRevoked = new RevocationInterval() // { // From = 0, // To = new DateTimeOffset(DateTime.Now, TimeSpan.Zero).ToUnixTimeSeconds() // } }; configuration.RequestedAttributes.ForEach(delegate(RequestedAttribute reqAttribute) { string referent = !String.IsNullOrEmpty(reqAttribute.Label) ? reqAttribute.Label : Guid.NewGuid().ToString(); reqAttribute.Label = null; // purge unsupported value from object that will be sent to aca-py if (!presentationRequest_1_0.RequestedAttributes.ContainsKey(referent)) { presentationRequest_1_0.RequestedAttributes.Add(referent, reqAttribute); } else { presentationRequest_1_0.RequestedAttributes.Add(disambiguateReferent(referent), reqAttribute); } }); configuration.RequestedPredicates.ForEach(delegate(RequestedPredicate reqPredicate) { string referent = !String.IsNullOrEmpty(reqPredicate.Label) ? reqPredicate.Label : Guid.NewGuid().ToString(); reqPredicate.Label = null; // purge unsupported value from object that will be sent to aca-py if (!presentationRequest_1_0.RequestedPredicates.ContainsKey(referent)) { presentationRequest_1_0.RequestedPredicates.Add(referent, reqPredicate); } else { presentationRequest_1_0.RequestedPredicates.Add(disambiguateReferent(referent), reqPredicate); } }); Dictionary <string, PresentationRequest_v_1_0> requestBody = new Dictionary <string, PresentationRequest_v_1_0>() { { "proof_request", presentationRequest_1_0 } }; return(JsonConvert.SerializeObject(requestBody, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore })); }
public static string GeneratePresentationRequest(this PresentationRequestConfiguration configuration) { PresentationRequest_v_1_0 presentationRequest_1_0 = new PresentationRequest_v_1_0() { Version = configuration.Version, Name = configuration.Name }; configuration.RequestedAttributes.ForEach(delegate(RequestedAttribute reqAttribute) { string referent = !String.IsNullOrEmpty(reqAttribute.Label) ? reqAttribute.Label : Guid.NewGuid().ToString(); reqAttribute.Label = null; // purge unsupported value from object that will be sent to aca-py if (!presentationRequest_1_0.RequestedAttributes.ContainsKey(referent)) { presentationRequest_1_0.RequestedAttributes.Add(referent, reqAttribute); } else { presentationRequest_1_0.RequestedAttributes.Add(disambiguateReferent(referent), reqAttribute); } }); configuration.RequestedPredicates.ForEach(delegate(RequestedPredicate reqPredicate) { string referent = !String.IsNullOrEmpty(reqPredicate.Label) ? reqPredicate.Label : Guid.NewGuid().ToString(); reqPredicate.Label = null; // purge unsupported value from object that will be sent to aca-py if (!presentationRequest_1_0.RequestedPredicates.ContainsKey(referent)) { presentationRequest_1_0.RequestedPredicates.Add(referent, reqPredicate); } else { presentationRequest_1_0.RequestedPredicates.Add(disambiguateReferent(referent), reqPredicate); } }); Dictionary <string, PresentationRequest_v_1_0> requestBody = new Dictionary <string, PresentationRequest_v_1_0>() { { "proof_request", presentationRequest_1_0 } }; return(JsonConvert.SerializeObject(requestBody)); }
public async Task <CreatePresentationResponse> CreatePresentationRequestAsync(PresentationRequestConfiguration configuration) { try { // Build appropriate json request body string jsonRequestBody = configuration.GeneratePresentationRequest(); var httpContent = new StringContent(jsonRequestBody, Encoding.UTF8, "application/json"); if (!string.IsNullOrEmpty(_adminUrlApiKey)) { httpContent.Headers.Add(ACAPYConstants.ApiKeyHeader, _adminUrlApiKey); } var response = await _httpClient.PostAsync($"{_adminUrl}{ACAPYConstants.PresentProofCreateRequest}", httpContent); var responseContent = await response.Content.ReadAsStringAsync(); _logger.LogDebug($"Status: [{response.StatusCode}], Content: [{responseContent}, Headers: [{response.Headers}]"); switch (response.StatusCode) { case HttpStatusCode.OK: return(JsonConvert.DeserializeObject <CreatePresentationResponse>(responseContent)); default: throw new Exception($"Create presentation request error . Code: {response.StatusCode}"); } } catch (Exception e) { throw new Exception("Create presentation request failed .", e); } }