Skip to content

Commit

Permalink
refactor: Replace query params auth with Header
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Dec 2, 2024
1 parent b4cc357 commit 39a2643
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ updates:
- package-ecosystem: 'maven'
directory: '/'
schedule:
interval: 'weekly'
interval: 'monthly'
commit-message:
prefix: 'build'
ignore:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public String getApiKey() {
* Converts this to a {@linkplain QueryParamsAuthMethod}.
*
* @return A new {@linkplain ApiKeyQueryParamsAuthMethod} with this object's API key and secret.
* @deprecated This will be removed in a future release.
*/
@Deprecated
public QueryParamsAuthMethod asQueryParams() {
return new ApiKeyQueryParamsAuthMethod(apiKey, apiSecret);
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/vonage/client/insight/InsightClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package com.vonage.client.insight;

import com.vonage.client.*;
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
import com.vonage.client.auth.AuthMethod;
import com.vonage.client.auth.SignatureAuthMethod;
import com.vonage.client.common.HttpMethod;
import java.util.function.Function;
Expand All @@ -38,10 +40,10 @@ public class InsightClient {
public InsightClient(HttpWrapper wrapper) {
@SuppressWarnings("unchecked")
final class Endpoint<T, R> extends DynamicEndpoint<T, R> {
Endpoint(Function<T, String> pathGetter, R... type) {
Endpoint(Function<T, String> pathGetter, Class<? extends AuthMethod> auth, R... type) {
super(DynamicEndpoint.<T, R> builder(type)
.wrapper(wrapper).requestMethod(HttpMethod.POST)
.authMethod(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class)
.authMethod(SignatureAuthMethod.class, auth)
.pathGetter((de, req) -> {
String base = de.getHttpWrapper().getHttpConfig().getApiBaseUri();
return base + "/ni/" + pathGetter.apply(req) + "/json";
Expand All @@ -50,9 +52,9 @@ final class Endpoint<T, R> extends DynamicEndpoint<T, R> {
}
}

basic = new Endpoint<>(req -> "basic");
standard = new Endpoint<>(req -> "standard");
advanced = new Endpoint<>(req -> "advanced" + (req.isAsync() ? "/async" : ""));
basic = new Endpoint<>(req -> "basic", ApiKeyHeaderAuthMethod.class);
standard = new Endpoint<>(req -> "standard", ApiKeyQueryParamsAuthMethod.class);
advanced = new Endpoint<>(req -> "advanced" + (req.isAsync() ? "/async" : ""), ApiKeyQueryParamsAuthMethod.class);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/vonage/client/sms/SmsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vonage.client.sms;

import com.vonage.client.*;
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
import com.vonage.client.auth.SignatureAuthMethod;
import com.vonage.client.common.HttpMethod;
Expand All @@ -40,7 +41,7 @@ class Endpoint extends DynamicEndpoint<Message, SmsSubmissionResponse> {
Endpoint() {
super(DynamicEndpoint.<Message, SmsSubmissionResponse> builder(SmsSubmissionResponse.class)
.wrapper(wrapper).requestMethod(HttpMethod.POST)
.authMethod(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class)
.authMethod(SignatureAuthMethod.class, ApiKeyHeaderAuthMethod.class)
.urlFormEncodedContentType(true).pathGetter((de, req) ->
de.getHttpWrapper().getHttpConfig().getRestBaseUri() + "/sms/json"
)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/vonage/client/verify/VerifyClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vonage.client.verify;

import com.vonage.client.*;
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
import com.vonage.client.common.HttpMethod;
import java.util.Locale;
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/com/vonage/client/insight/InsightClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@

import com.vonage.client.AbstractClientTest;
import com.vonage.client.RestEndpoint;
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
import com.vonage.client.auth.AuthMethod;
import com.vonage.client.auth.SignatureAuthMethod;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

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

@Override
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
return List.of(SignatureAuthMethod.class, ApiKeyHeaderAuthMethod.class);
}

@Override
protected String expectedEndpointUri(BasicInsightRequest request) {
return "/ni/basic/json";
Expand Down Expand Up @@ -254,6 +265,11 @@ protected RestEndpoint<StandardInsightRequest, StandardInsightResponse> endpoint
return client.standard;
}

@Override
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
return List.of(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class);
}

@Override
protected String expectedEndpointUri(StandardInsightRequest request) {
return "/ni/standard/json";
Expand Down Expand Up @@ -288,6 +304,11 @@ protected RestEndpoint<AdvancedInsightRequest, AdvancedInsightResponse> endpoint
return client.advanced;
}

@Override
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
return List.of(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class);
}

@Override
protected String expectedEndpointUri(AdvancedInsightRequest request) {
return request.isAsync() ? "/ni/advanced/async/json" : "/ni/advanced/json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@

import com.vonage.client.DynamicEndpointTestSpec;
import com.vonage.client.VonageApiResponseException;
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
import com.vonage.client.auth.AuthMethod;
import com.vonage.client.auth.SignatureAuthMethod;
import com.vonage.client.common.HttpMethod;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

abstract class InsightEndpointTestSpec<T, R> extends DynamicEndpointTestSpec<T, R> {

@Override
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
return Arrays.asList(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class);
}

@Override
protected Class<? extends VonageApiResponseException> expectedResponseExceptionType() {
return VonageApiResponseException.class;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/vonage/client/sms/SmsEndpointTestSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.vonage.client.DynamicEndpointTestSpec;
import com.vonage.client.RestEndpoint;
import com.vonage.client.VonageApiResponseException;
import com.vonage.client.auth.ApiKeyQueryParamsAuthMethod;
import com.vonage.client.auth.ApiKeyHeaderAuthMethod;
import com.vonage.client.auth.AuthMethod;
import com.vonage.client.auth.SignatureAuthMethod;
import com.vonage.client.common.HttpMethod;
Expand Down Expand Up @@ -47,7 +47,7 @@ protected HttpMethod expectedHttpMethod() {

@Override
protected Collection<Class<? extends AuthMethod>> expectedAuthMethods() {
return Arrays.asList(SignatureAuthMethod.class, ApiKeyQueryParamsAuthMethod.class);
return Arrays.asList(SignatureAuthMethod.class, ApiKeyHeaderAuthMethod.class);
}

@Override
Expand Down

0 comments on commit 39a2643

Please sign in to comment.