Skip to content

Commit fabbd00

Browse files
authored
fix: Use Basic header auth in InsightClient (#569)
1 parent 3835741 commit fabbd00

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1111
- Deprecated `java.util.Date`-based methods
1212
- `getOrder()` returns a `com.vonage.client.common.SortOrder` instead of `CallOrder`
1313
- Made constructors for response objects in Voice API package-private
14+
- Basic auth header in Number Insight v1 requests instead of query parameters
1415

1516
# [8.16.2] - 2025-02-05
1617
- Added `disconnected_by` enum to `com.vonage.client.voice.EventWebhook`

src/main/java/com/vonage/client/insight/InsightClient.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
import com.vonage.client.*;
1919
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
20-
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
21-
import com.vonage.client.auth.AuthMethod;
2220
import com.vonage.client.auth.SignatureAuthMethod;
2321
import com.vonage.client.common.HttpMethod;
2422
import java.util.function.Function;
@@ -40,10 +38,10 @@ public class InsightClient {
4038
public InsightClient(HttpWrapper wrapper) {
4139
@SuppressWarnings("unchecked")
4240
final class Endpoint<T, R> extends DynamicEndpoint<T, R> {
43-
Endpoint(Function<T, String> pathGetter, Class<? extends AuthMethod> auth, R... type) {
41+
Endpoint(Function<T, String> pathGetter, R... type) {
4442
super(DynamicEndpoint.<T, R> builder(type)
4543
.wrapper(wrapper).requestMethod(HttpMethod.POST)
46-
.authMethod(SignatureAuthMethod.class, auth)
44+
.authMethod(SignatureAuthMethod.class, ApiKeyHeaderAuthMethod.class)
4745
.pathGetter((de, req) -> {
4846
String base = de.getHttpWrapper().getHttpConfig().getApiBaseUri();
4947
return base + "/ni/" + pathGetter.apply(req) + "/json";
@@ -52,9 +50,9 @@ final class Endpoint<T, R> extends DynamicEndpoint<T, R> {
5250
}
5351
}
5452

55-
basic = new Endpoint<>(req -> "basic", ApiKeyHeaderAuthMethod.class);
56-
standard = new Endpoint<>(req -> "standard", ApiKeyQueryParamsAuthMethod.class);
57-
advanced = new Endpoint<>(req -> "advanced" + (req.isAsync() ? "/async" : ""), ApiKeyQueryParamsAuthMethod.class);
53+
basic = new Endpoint<>(req -> "basic");
54+
standard = new Endpoint<>(req -> "standard");
55+
advanced = new Endpoint<>(req -> "advanced" + (req.isAsync() ? "/async" : ""));
5856
}
5957

6058
/**

src/test/java/com/vonage/client/insight/InsightClientTest.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717

1818
import com.vonage.client.AbstractClientTest;
1919
import com.vonage.client.RestEndpoint;
20-
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
21-
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
22-
import com.vonage.client.auth.AuthMethod;
23-
import com.vonage.client.auth.SignatureAuthMethod;
24-
import org.junit.jupiter.api.*;
2520
import static org.junit.jupiter.api.Assertions.*;
21+
import org.junit.jupiter.api.*;
2622
import java.math.BigDecimal;
27-
import java.util.Collection;
2823
import java.util.LinkedHashMap;
29-
import java.util.List;
3024
import java.util.Map;
3125

3226
public class InsightClientTest extends AbstractClientTest<InsightClient> {
@@ -228,11 +222,6 @@ protected RestEndpoint<BasicInsightRequest, BasicInsightResponse> endpoint() {
228222
return client.basic;
229223
}
230224

231-
@Override
232-
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
233-
return List.of(SignatureAuthMethod.class, ApiKeyHeaderAuthMethod.class);
234-
}
235-
236225
@Override
237226
protected String expectedEndpointUri(BasicInsightRequest request) {
238227
return "/ni/basic/json";
@@ -265,11 +254,6 @@ protected RestEndpoint<StandardInsightRequest, StandardInsightResponse> endpoint
265254
return client.standard;
266255
}
267256

268-
@Override
269-
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
270-
return List.of(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class);
271-
}
272-
273257
@Override
274258
protected String expectedEndpointUri(StandardInsightRequest request) {
275259
return "/ni/standard/json";
@@ -304,11 +288,6 @@ protected RestEndpoint<AdvancedInsightRequest, AdvancedInsightResponse> endpoint
304288
return client.advanced;
305289
}
306290

307-
@Override
308-
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
309-
return List.of(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class);
310-
}
311-
312291
@Override
313292
protected String expectedEndpointUri(AdvancedInsightRequest request) {
314293
return request.isAsync() ? "/ni/advanced/async/json" : "/ni/advanced/json";

src/test/java/com/vonage/client/insight/InsightEndpointTestSpec.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717

1818
import com.vonage.client.DynamicEndpointTestSpec;
1919
import com.vonage.client.VonageApiResponseException;
20+
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
21+
import com.vonage.client.auth.AuthMethod;
22+
import com.vonage.client.auth.SignatureAuthMethod;
2023
import com.vonage.client.common.HttpMethod;
24+
import java.util.Collection;
25+
import java.util.List;
2126
import java.util.Map;
2227

2328
abstract class InsightEndpointTestSpec<T, R> extends DynamicEndpointTestSpec<T, R> {
@@ -27,6 +32,11 @@ protected Class<? extends VonageApiResponseException> expectedResponseExceptionT
2732
return VonageApiResponseException.class;
2833
}
2934

35+
@Override
36+
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
37+
return List.of(SignatureAuthMethod.class, ApiKeyHeaderAuthMethod.class);
38+
}
39+
3040
@Override
3141
protected String expectedDefaultBaseUri() {
3242
return "https://api.nexmo.com";

0 commit comments

Comments
 (0)