From 492662ba86027c26c126c584f3356d015ac2ce8d Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Mon, 6 Oct 2025 14:39:20 +0100 Subject: [PATCH 1/2] collection of issues fixed --- .../TheSMSWorks/TheSmsWorksProxy.cs | 23 +++++++++++++------ MessagingService/Common/Extensions.cs | 5 +++- .../Controllers/DomainEventController.cs | 1 + .../Controllers/EmailController.cs | 4 +++- MessagingService/Controllers/SMSController.cs | 4 +++- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs index c1badba..f54b2f9 100644 --- a/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs +++ b/MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs @@ -25,6 +25,11 @@ public TheSmsWorksProxy(HttpClient httpClient) { this.HttpClient = httpClient; } + private const String TheSMSWorksBaseAddressKey = "TheSMSWorksBaseAddress"; + private const String TheSMSWorksCustomerIdKey = "TheSMSWorksCustomerId"; + private const String TheSMSWorksKeyKey = "TheSMSWorksKey"; + private const String TheSMSWorksSecretKey = "TheSMSWorksSecret"; + /// /// Sends the SMS. /// @@ -42,13 +47,14 @@ public async Task SendSMS(Guid messageId, SMSServiceProxyResponse response = null; // Create the Auth Request - TheSmsWorksTokenRequest apiTokenRequest = new() { CustomerId = ConfigurationReader.GetValue("TheSMSWorksCustomerId"), Key = ConfigurationReader.GetValue("TheSMSWorksKey"), Secret = ConfigurationReader.GetValue("TheSMSWorksSecret") }; + TheSmsWorksTokenRequest apiTokenRequest = new() { CustomerId = ConfigurationReader.GetValue(TheSMSWorksCustomerIdKey), + Key = ConfigurationReader.GetValue(TheSMSWorksKeyKey), Secret = ConfigurationReader.GetValue(TheSMSWorksSecretKey) }; String apiTokenRequestSerialised = JsonConvert.SerializeObject(apiTokenRequest).ToLower(); StringContent content = new(apiTokenRequestSerialised, Encoding.UTF8, "application/json"); // First do the authentication - HttpResponseMessage apiTokenHttpResponse = await this.HttpClient.PostAsync($"{ConfigurationReader.GetValue("TheSMSWorksBaseAddress")}auth/token", content, cancellationToken); + HttpResponseMessage apiTokenHttpResponse = await this.HttpClient.PostAsync($"{ConfigurationReader.GetValue(TheSMSWorksBaseAddressKey)}auth/token", content, cancellationToken); if (apiTokenHttpResponse.IsSuccessStatusCode) { TheSmsWorksTokenResponse apiTokenResponse = JsonConvert.DeserializeObject(await apiTokenHttpResponse.Content.ReadAsStringAsync()); @@ -67,7 +73,7 @@ public async Task SendSMS(Guid messageId, content = new StringContent(apiSendSMSMessageRequestSerialised, Encoding.UTF8, "application/json"); this.HttpClient.DefaultRequestHeaders.Add("Authorization", apiTokenResponse.Token); - HttpResponseMessage apiSendSMSMessageHttpResponse = await this.HttpClient.PostAsync($"{ConfigurationReader.GetValue("TheSMSWorksBaseAddress")}message/send", content, cancellationToken); + HttpResponseMessage apiSendSMSMessageHttpResponse = await this.HttpClient.PostAsync($"{ConfigurationReader.GetValue(TheSMSWorksBaseAddressKey)}message/send", content, cancellationToken); if (apiSendSMSMessageHttpResponse.IsSuccessStatusCode) { // Message has been sent @@ -91,19 +97,22 @@ public async Task GetMessageStatus(String providerReferen MessageStatusResponse response = new(); // Create the Auth Request - TheSmsWorksTokenRequest apiTokenRequest = new() { CustomerId = ConfigurationReader.GetValue("TheSMSWorksCustomerId"), Key = ConfigurationReader.GetValue("TheSMSWorksKey"), Secret = ConfigurationReader.GetValue("TheSMSWorksSecret") }; + TheSmsWorksTokenRequest apiTokenRequest = new() { CustomerId = ConfigurationReader.GetValue(TheSMSWorksCustomerIdKey), + Key = ConfigurationReader.GetValue(TheSMSWorksKeyKey), + Secret = ConfigurationReader.GetValue(TheSMSWorksSecretKey) + }; String apiTokenRequestSerialised = JsonConvert.SerializeObject(apiTokenRequest).ToLower(); StringContent content = new(apiTokenRequestSerialised, Encoding.UTF8, "application/json"); // First do the authentication - HttpResponseMessage apiTokenHttpResponse = await this.HttpClient.PostAsync($"{ConfigurationReader.GetValue("TheSMSWorksBaseAddress")}auth/token", content, cancellationToken); + HttpResponseMessage apiTokenHttpResponse = await this.HttpClient.PostAsync($"{ConfigurationReader.GetValue(TheSMSWorksBaseAddressKey)}auth/token", content, cancellationToken); if (apiTokenHttpResponse.IsSuccessStatusCode) { - TheSmsWorksTokenResponse apiTokenResponse = JsonConvert.DeserializeObject(await apiTokenHttpResponse.Content.ReadAsStringAsync()); + TheSmsWorksTokenResponse apiTokenResponse = JsonConvert.DeserializeObject(await apiTokenHttpResponse.Content.ReadAsStringAsync(cancellationToken)); this.HttpClient.DefaultRequestHeaders.Add("Authorization", apiTokenResponse.Token); - HttpResponseMessage apiGetSMSMessageHttpResponse = await this.HttpClient.GetAsync($"{ConfigurationReader.GetValue("TheSMSWorksBaseAddress")}messages/{providerReference}", cancellationToken); + HttpResponseMessage apiGetSMSMessageHttpResponse = await this.HttpClient.GetAsync($"{ConfigurationReader.GetValue(TheSMSWorksBaseAddressKey)}messages/{providerReference}", cancellationToken); if (apiGetSMSMessageHttpResponse.IsSuccessStatusCode) { // Message has been sent diff --git a/MessagingService/Common/Extensions.cs b/MessagingService/Common/Extensions.cs index 2e78479..ce9bd93 100644 --- a/MessagingService/Common/Extensions.cs +++ b/MessagingService/Common/Extensions.cs @@ -41,6 +41,9 @@ public static class Extensions case TraceEventType.Verbose: Logger.LogDebug(logMessage); break; + default: + Logger.LogInformation(logMessage); + break; } }; @@ -62,7 +65,7 @@ public static void PreWarm(this IApplicationBuilder applicationBuilder) String connectionString = Startup.Configuration.GetValue("EventStoreSettings:ConnectionString"); - EventStoreClientSettings eventStoreConnectionSettings = EventStoreClientSettings.Create(connectionString); + applicationBuilder.ConfigureSubscriptionService(subscriptionWorkersRoot, connectionString, eventHandlerResolvers, diff --git a/MessagingService/Controllers/DomainEventController.cs b/MessagingService/Controllers/DomainEventController.cs index 4efff4e..1931e35 100644 --- a/MessagingService/Controllers/DomainEventController.cs +++ b/MessagingService/Controllers/DomainEventController.cs @@ -57,6 +57,7 @@ public DomainEventController(IDomainEventHandlerResolver domainEventHandlerResol /// The domain event. /// The cancellation token. /// + [ValidateAntiForgeryToken] [HttpPost] public async Task PostEventAsync([FromBody] Object request, CancellationToken cancellationToken) { diff --git a/MessagingService/Controllers/EmailController.cs b/MessagingService/Controllers/EmailController.cs index 795bb4e..69e0cf2 100644 --- a/MessagingService/Controllers/EmailController.cs +++ b/MessagingService/Controllers/EmailController.cs @@ -55,13 +55,14 @@ public EmailController(IMediator mediator) #endregion #region Methods - + /// /// Sends the email. /// /// The send email request. /// The cancellation token. /// + [ValidateAntiForgeryToken] [HttpPost] [Route("")] [SwaggerResponse(201, "Created", typeof(SendEmailResponseDTO))] @@ -105,6 +106,7 @@ public async Task SendEmail([FromBody] SendEmailRequestDTO sendEm return result.ToActionResultX(); } + [ValidateAntiForgeryToken] [HttpPost] [Route("resend")] [SwaggerResponse(202, "Accepted", typeof(SendEmailResponseDTO))] diff --git a/MessagingService/Controllers/SMSController.cs b/MessagingService/Controllers/SMSController.cs index 15115fd..8ab2d8b 100644 --- a/MessagingService/Controllers/SMSController.cs +++ b/MessagingService/Controllers/SMSController.cs @@ -48,13 +48,14 @@ public SMSController(IMediator mediator) #endregion #region Methods - + /// /// Sends the SMS. /// /// The send SMS request. /// The cancellation token. /// + [ValidateAntiForgeryToken] [HttpPost] [Route("")] [SwaggerResponse(201, "Created", typeof(SendSMSResponse))] @@ -83,6 +84,7 @@ public async Task SendSMS([FromBody] SendSMSRequest sendSMSReques return result.ToActionResultX(); } + [ValidateAntiForgeryToken] [HttpPost] [Route("resend")] [SwaggerResponse(202, "Accepted", typeof(SendSMSResponse))] From 519a54dd866156aa562154a52f68762b3cd00128 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Mon, 6 Oct 2025 15:16:39 +0100 Subject: [PATCH 2/2] :| --- MessagingService/Controllers/DomainEventController.cs | 1 - MessagingService/Controllers/EmailController.cs | 1 - MessagingService/Controllers/SMSController.cs | 1 - 3 files changed, 3 deletions(-) diff --git a/MessagingService/Controllers/DomainEventController.cs b/MessagingService/Controllers/DomainEventController.cs index 1931e35..4efff4e 100644 --- a/MessagingService/Controllers/DomainEventController.cs +++ b/MessagingService/Controllers/DomainEventController.cs @@ -57,7 +57,6 @@ public DomainEventController(IDomainEventHandlerResolver domainEventHandlerResol /// The domain event. /// The cancellation token. /// - [ValidateAntiForgeryToken] [HttpPost] public async Task PostEventAsync([FromBody] Object request, CancellationToken cancellationToken) { diff --git a/MessagingService/Controllers/EmailController.cs b/MessagingService/Controllers/EmailController.cs index 69e0cf2..e129a42 100644 --- a/MessagingService/Controllers/EmailController.cs +++ b/MessagingService/Controllers/EmailController.cs @@ -62,7 +62,6 @@ public EmailController(IMediator mediator) /// The send email request. /// The cancellation token. /// - [ValidateAntiForgeryToken] [HttpPost] [Route("")] [SwaggerResponse(201, "Created", typeof(SendEmailResponseDTO))] diff --git a/MessagingService/Controllers/SMSController.cs b/MessagingService/Controllers/SMSController.cs index 8ab2d8b..5b89539 100644 --- a/MessagingService/Controllers/SMSController.cs +++ b/MessagingService/Controllers/SMSController.cs @@ -55,7 +55,6 @@ public SMSController(IMediator mediator) /// The send SMS request. /// The cancellation token. /// - [ValidateAntiForgeryToken] [HttpPost] [Route("")] [SwaggerResponse(201, "Created", typeof(SendSMSResponse))]