Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
this.HttpClient = httpClient;
}

private const String TheSMSWorksBaseAddressKey = "TheSMSWorksBaseAddress";
private const String TheSMSWorksCustomerIdKey = "TheSMSWorksCustomerId";
private const String TheSMSWorksKeyKey = "TheSMSWorksKey";
private const String TheSMSWorksSecretKey = "TheSMSWorksSecret";

Check failure on line 31 in MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

MessagingService.BusinessLogic/Services/SMSServices/TheSMSWorks/TheSmsWorksProxy.cs#L31

Hardcoded passwords are a security risk.

/// <summary>
/// Sends the SMS.
/// </summary>
Expand All @@ -42,13 +47,14 @@
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<TheSmsWorksTokenResponse>(await apiTokenHttpResponse.Content.ReadAsStringAsync());
Expand All @@ -67,7 +73,7 @@
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
Expand All @@ -91,19 +97,22 @@
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<TheSmsWorksTokenResponse>(await apiTokenHttpResponse.Content.ReadAsStringAsync());
TheSmsWorksTokenResponse apiTokenResponse = JsonConvert.DeserializeObject<TheSmsWorksTokenResponse>(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
Expand Down
5 changes: 4 additions & 1 deletion MessagingService/Common/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static class Extensions
case TraceEventType.Verbose:
Logger.LogDebug(logMessage);
break;
default:
Logger.LogInformation(logMessage);
break;
}
};

Expand All @@ -62,7 +65,7 @@ public static void PreWarm(this IApplicationBuilder applicationBuilder)


String connectionString = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString");
EventStoreClientSettings eventStoreConnectionSettings = EventStoreClientSettings.Create(connectionString);

applicationBuilder.ConfigureSubscriptionService(subscriptionWorkersRoot,
connectionString,
eventHandlerResolvers,
Expand Down
3 changes: 2 additions & 1 deletion MessagingService/Controllers/EmailController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public EmailController(IMediator mediator)
#endregion

#region Methods

/// <summary>
/// Sends the email.
/// </summary>
Expand Down Expand Up @@ -105,6 +105,7 @@ public async Task<IActionResult> SendEmail([FromBody] SendEmailRequestDTO sendEm
return result.ToActionResultX();
}

[ValidateAntiForgeryToken]
[HttpPost]
[Route("resend")]
[SwaggerResponse(202, "Accepted", typeof(SendEmailResponseDTO))]
Expand Down
3 changes: 2 additions & 1 deletion MessagingService/Controllers/SMSController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public SMSController(IMediator mediator)
#endregion

#region Methods

/// <summary>
/// Sends the SMS.
/// </summary>
Expand Down Expand Up @@ -83,6 +83,7 @@ public async Task<IActionResult> SendSMS([FromBody] SendSMSRequest sendSMSReques
return result.ToActionResultX();
}

[ValidateAntiForgeryToken]
[HttpPost]
[Route("resend")]
[SwaggerResponse(202, "Accepted", typeof(SendSMSResponse))]
Expand Down
Loading