Skip to content

Commit

Permalink
feat: use specific clients for OIDC requests in NumberVerification
Browse files Browse the repository at this point in the history
  • Loading branch information
Tr00d committed Jun 20, 2024
1 parent 3172720 commit c468a60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Vonage/NumberVerification/NumberVerificationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ namespace Vonage.NumberVerification;

internal class NumberVerificationClient : INumberVerificationClient
{
private readonly VonageHttpClient authorizationClient;
private readonly VonageHttpClient vonageClient;

internal NumberVerificationClient(VonageHttpClientConfiguration configuration) =>
internal NumberVerificationClient(VonageHttpClientConfiguration configuration,
VonageHttpClientConfiguration authorizationConfiguration)
{
this.vonageClient = new VonageHttpClient(configuration, JsonSerializerBuilder.BuildWithSnakeCase());
this.authorizationClient =
new VonageHttpClient(authorizationConfiguration, JsonSerializerBuilder.BuildWithSnakeCase());
}

/// <inheritdoc />
public Task<Result<AuthenticateResponse>> AuthenticateAsync(Result<AuthenticateRequest> request) =>
Expand Down Expand Up @@ -49,7 +55,7 @@ await request
this.vonageClient.SendWithResponseAsync<GetTokenRequest, GetTokenResponse>(request);

private Task<Result<AuthorizeResponse>> SendAuthorizeRequest(AuthorizeRequest request) =>
this.vonageClient.SendWithResponseAsync<AuthorizeRequest, AuthorizeResponse>(request);
this.authorizationClient.SendWithResponseAsync<AuthorizeRequest, AuthorizeResponse>(request);

private static GetTokenRequest BuildGetTokenRequest(AuthorizeResponse request) => request.BuildGetTokenRequest();

Expand Down
6 changes: 4 additions & 2 deletions Vonage/VonageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public Credentials Credentials
public INumberVerificationClient NumberVerificationClient { get; private set; }

private VonageHttpClientConfiguration BuildConfiguration(HttpClient client) =>
new(client, this.Credentials.GetAuthenticationHeader(), this.Credentials.GetUserAgent());
new VonageHttpClientConfiguration(client, this.Credentials.GetAuthenticationHeader(),
this.Credentials.GetUserAgent());

private Configuration GetConfiguration() => this.configuration.IfNone(Configuration.Instance);

Expand All @@ -166,6 +167,7 @@ private void PropagateCredentials()
var videoConfiguration = this.BuildConfiguration(currentConfiguration.BuildHttpClientForVideo());
var euConfiguration =
this.BuildConfiguration(currentConfiguration.BuildHttpClientForRegion(VonageUrls.Region.EU));
var oidcConfiguration = this.BuildConfiguration(currentConfiguration.BuildHttpClientForOidc());
this.VerifyV2Client = new VerifyV2Client(nexmoConfiguration);
this.SubAccountsClient = new SubAccountsClient(nexmoConfiguration, this.Credentials.ApiKey);
this.NumberInsightV2Client = new NumberInsightV2Client(nexmoConfiguration);
Expand All @@ -174,7 +176,7 @@ private void PropagateCredentials()
this.MeetingsClient = new MeetingsClient(euConfiguration, new FileSystem());
this.ProactiveConnectClient = new ProactiveConnectClient(euConfiguration);
this.SimSwapClient = new SimSwapClient(euConfiguration);
this.NumberVerificationClient = new NumberVerificationClient(euConfiguration);
this.NumberVerificationClient = new NumberVerificationClient(euConfiguration, oidcConfiguration);
this.VideoClient = new VideoClient(videoConfiguration);
}
}

0 comments on commit c468a60

Please sign in to comment.