diff --git a/src/Sinch/Auth/ApplicationSignedAuth.cs b/src/Sinch/Auth/ApplicationSignedAuth.cs index 4cd1926a..46040abc 100644 --- a/src/Sinch/Auth/ApplicationSignedAuth.cs +++ b/src/Sinch/Auth/ApplicationSignedAuth.cs @@ -38,7 +38,7 @@ public string GetSignedAuth(byte[] jsonBodyBytes, string httpVerb, public Task 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); diff --git a/src/Sinch/SinchClient.cs b/src/Sinch/SinchClient.cs index f87e3f37..5ce1e3fa 100644 --- a/src/Sinch/SinchClient.cs +++ b/src/Sinch/SinchClient.cs @@ -120,7 +120,11 @@ public class SinchClient : ISinchClient private const string SmsApiUrlTemplate = "https://zt.{0}.sms.api.sinch.com"; private const string SmsApiServicePlanIdUrlTemplate = "https://{0}.sms.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/"; @@ -281,7 +285,8 @@ public ISinchVoiceClient Voice(string appKey, string appSecret, var http = new Http(auth, _httpClient, _loggerFactory?.Create(), 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() diff --git a/src/Sinch/Voice/SinchVoiceClient.cs b/src/Sinch/Voice/SinchVoiceClient.cs index 6eb30e9a..65c8a948 100644 --- a/src/Sinch/Voice/SinchVoiceClient.cs +++ b/src/Sinch/Voice/SinchVoiceClient.cs @@ -57,14 +57,15 @@ internal class SinchVoiceClient : ISinchVoiceClient private readonly ILoggerAdapter? _logger; public SinchVoiceClient(Uri baseAddress, LoggerFactory? loggerFactory, - IHttp http, ApplicationSignedAuth applicationSignedAuth) + IHttp http, ApplicationSignedAuth applicationSignedAuth, Uri applicationManagementBaseAddress) { _applicationSignedAuth = applicationSignedAuth; _logger = loggerFactory?.Create(); Callouts = new SinchCallout(loggerFactory?.Create(), baseAddress, http); Calls = new SinchCalls(loggerFactory?.Create(), baseAddress, http); Conferences = new SinchConferences(loggerFactory?.Create(), baseAddress, http); - Applications = new SinchApplications(loggerFactory?.Create(), baseAddress, http); + Applications = new SinchApplications(loggerFactory?.Create(), + applicationManagementBaseAddress, http); } /// diff --git a/tests/Sinch.Tests/AuthTests.cs b/tests/Sinch.Tests/AuthTests.cs index 714fab32..7a3738af 100644 --- a/tests/Sinch.Tests/AuthTests.cs +++ b/tests/Sinch.Tests/AuthTests.cs @@ -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");