private static HttpRequestMessage BuildRequest(string requestBody, ISchemaWebhookUrlEntity webhook) { var request = new HttpRequestMessage(HttpMethod.Post, webhook.Url) { Content = new StringContent(requestBody, Encoding.UTF8, "application/json") }; return(request); }
private static JObject SignPayload(JObject payload, ISchemaWebhookUrlEntity webhook) { payload = new JObject(payload); var eventTimestamp = SystemClock.Instance.GetCurrentInstant().ToUnixTimeSeconds(); var eventSignature = $"{eventTimestamp}{webhook.SharedSecret}".Sha256Base64(); payload["signature"] = eventSignature; return(payload); }
private async Task EnqueueJobAsync(string payload, ISchemaWebhookUrlEntity webhook, AppEvent contentEvent, string eventName, Instant now) { var signature = $"{payload}{webhook.SharedSecret}".Sha256Base64(); var job = new WebhookJob { Id = Guid.NewGuid(), AppId = contentEvent.AppId.Id, RequestUrl = webhook.Url, RequestBody = payload, RequestSignature = signature, EventName = eventName, Expires = now.Plus(ExpirationTime), WebhookId = webhook.Id }; await webhookEventRepository.EnqueueAsync(job, now); }