public WebHookPublisher(WebHookPublisherSettings settings) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); _webHooksRepository = new WebHooksRepository(settings.StreamStore, "webhooks", settings.GetUtcNow, settings.MaxWebHookCount); _httpClient = new HttpClient(settings.HttpMessageHandler); _streamStore = settings.StreamStore; _webHookHeaders = new WebHookHeaders(settings.Vendor); }
private void SetCustomHeaders(HttpRequestMessage postEventRequest, string eventName, Guid messageId, string signature) { var headers = new WebHookHeaders(_subscriberSettings.Vendor); postEventRequest.Headers.TryAddWithoutValidation(headers.EventNameHeader, eventName); postEventRequest.Headers.TryAddWithoutValidation(headers.MessageIdHeader, messageId.ToString("d")); postEventRequest.Headers.TryAddWithoutValidation(headers.SequenceHeader, "1"); postEventRequest.Headers.TryAddWithoutValidation(headers.SignatureHeader, signature); }
/// <inheritdoc /> /// <summary> /// </summary> /// <returns></returns> public override async Task <string> GetTokenAsync(CancellationToken cancellationToken) { if (string.IsNullOrEmpty(OidcAuthenticationConfig.ClientId)) { throw new ArgumentNullException(nameof(OidcAuthenticationConfig.ClientId)); } if (string.IsNullOrEmpty(OidcAuthenticationConfig.ClientSecret)) { throw new ArgumentNullException(nameof(OidcAuthenticationConfig.ClientSecret)); } var httpClient = HttpClientFactory.Get(OidcAuthenticationConfig.Uri); var headers = new WebHookHeaders(); headers.AddContentHeader(Constants.Headers.ContentType, "application/json-patch+json"); headers.AddRequestHeader("client_id", OidcAuthenticationConfig.ClientId); headers.AddRequestHeader("client_secret", OidcAuthenticationConfig.ClientSecret); var authProviderResponse = await httpClient.SendRequestReliablyAsync( HttpMethod.Post, new Uri(OidcAuthenticationConfig.Uri), headers, string.Empty, cancellationToken); if (authProviderResponse.StatusCode != HttpStatusCode.Created || authProviderResponse.Content == null) { throw new Exception("didn't get a token from the provider"); } var responseContent = await authProviderResponse.Content.ReadAsStringAsync(); var stsResult = JsonConvert.DeserializeObject <OidcAuthenticationToken>(responseContent); OidcAuthenticationToken = stsResult; BigBrother.Publish(new ClientTokenRequest { ClientId = OidcAuthenticationConfig.ClientId, Authority = OidcAuthenticationConfig.Uri }); return($"Bearer {stsResult.AccessToken}"); }