Skip to content

Commit

Permalink
Merge branch 'main' into feat/fax-api-faxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dovchik committed May 16, 2024
2 parents 442cf9e + bb7fe2b commit ba3b60d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Sinch/Auth/ApplicationSignedAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public string GetSignedAuth(byte[] jsonBodyBytes, string httpVerb,
public Task<string> GetAuthToken(bool force = false)
{
var encodedBody = string.Empty;
if (_jsonBodyInBytes is not null)
if (_jsonBodyInBytes is not null && _jsonBodyInBytes.Length > 0)
{
var md5Bytes = MD5.HashData(_jsonBodyInBytes);
encodedBody = Convert.ToBase64String(md5Bytes);
Expand Down
7 changes: 6 additions & 1 deletion src/Sinch/SinchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ public class SinchClient : ISinchClient
private const string FaxApiUrl = "https://fax.api.sinch.com/";
private const string FaxApiUrlTemplate = "https://{0}.fax.api.sinch.com/";
private const string ConversationApiUrlTemplate = "https://{0}.conversation.api.sinch.com/";

private const string VoiceApiUrlTemplate = "https://{0}.api.sinch.com/";

// apparently, management api for applications have a different set url
private const string VoiceApiApplicationManagementUrl = "https://callingapi.sinch.com/";
private const string AuthApiUrl = "https://auth.sinch.com";
private const string TemplatesApiUrlTemplate = "https://{0}.template.api.sinch.com/";

Expand Down Expand Up @@ -314,7 +318,8 @@ public ISinchVoiceClient Voice(string appKey, string appSecret,
var http = new Http(auth, _httpClient, _loggerFactory?.Create<IHttp>(), JsonNamingPolicy.CamelCase);
return new SinchVoiceClient(
new Uri(_apiUrlOverrides?.VoiceUrl ?? string.Format(VoiceApiUrlTemplate, voiceRegion.Value)),
_loggerFactory, http, (auth as ApplicationSignedAuth)!);
_loggerFactory, http, (auth as ApplicationSignedAuth)!,
new Uri(_apiUrlOverrides?.VoiceUrl ?? VoiceApiApplicationManagementUrl));
}

private void ValidateCommonCredentials()
Expand Down
5 changes: 3 additions & 2 deletions src/Sinch/Voice/SinchVoiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ internal class SinchVoiceClient : ISinchVoiceClient
private readonly ILoggerAdapter<ISinchVoiceClient>? _logger;

public SinchVoiceClient(Uri baseAddress, LoggerFactory? loggerFactory,
IHttp http, ApplicationSignedAuth applicationSignedAuth)
IHttp http, ApplicationSignedAuth applicationSignedAuth, Uri applicationManagementBaseAddress)
{
_applicationSignedAuth = applicationSignedAuth;
_logger = loggerFactory?.Create<ISinchVoiceClient>();
Callouts = new SinchCallout(loggerFactory?.Create<ISinchVoiceCallout>(), baseAddress, http);
Calls = new SinchCalls(loggerFactory?.Create<ISinchVoiceCalls>(), baseAddress, http);
Conferences = new SinchConferences(loggerFactory?.Create<ISinchVoiceConferences>(), baseAddress, http);
Applications = new SinchApplications(loggerFactory?.Create<ISinchVoiceApplications>(), baseAddress, http);
Applications = new SinchApplications(loggerFactory?.Create<ISinchVoiceApplications>(),
applicationManagementBaseAddress, http);
}

/// <inheritdoc />
Expand Down
8 changes: 5 additions & 3 deletions tests/Sinch.Tests/AuthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ public void GenerateCorrectApplicationSignature()
.BeEquivalentTo("669E367E-6BBA-48AB-AF15-266871C28135:h6rXrFayOoggyHW4ymnLlfSDkZZPg6j98lHzvOXVjvw=");
}

[Fact]
public void AppSignatureWithEmptyBody()
[Theory]
[InlineData(new byte[0])]
[InlineData(null)]
public void AppSignatureWithEmptyBody(byte[] data)
{
var auth = new ApplicationSignedAuth("669E367E-6BBA-48AB-AF15-266871C28135", "BeIukql3pTKJ8RGL5zo0DA==");

var result = auth.GetSignedAuth(null, "POST", "/verification/v1/verifications",
var result = auth.GetSignedAuth(data, "POST", "/verification/v1/verifications",
"x-timestamp:2014-06-04T13:41:58Z",
"application/json");

Expand Down

0 comments on commit ba3b60d

Please sign in to comment.