diff --git a/src/main/java/com/vonage/client/verify2/SilentAuthWorkflow.java b/src/main/java/com/vonage/client/verify2/SilentAuthWorkflow.java index 2b1a7c792..437f89863 100644 --- a/src/main/java/com/vonage/client/verify2/SilentAuthWorkflow.java +++ b/src/main/java/com/vonage/client/verify2/SilentAuthWorkflow.java @@ -16,6 +16,7 @@ package com.vonage.client.verify2; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Defines properties for mobile network-based authentication. See the @@ -24,6 +25,7 @@ */ @JsonInclude(value = JsonInclude.Include.NON_NULL) public final class SilentAuthWorkflow extends Workflow { + private Boolean sandbox; /** * Constructs a new Silent Auth verification workflow. @@ -33,4 +35,26 @@ public final class SilentAuthWorkflow extends Workflow { public SilentAuthWorkflow(String to) { super(Channel.SILENT_AUTH, to); } + + /** + * Constructs a new Silent Auth verification workflow. + * + * @param to The number to registered to the device on the network to authenticate. + */ + public SilentAuthWorkflow(String to, boolean sandbox) { + this(to); + this.sandbox = sandbox; + } + + /** + * Optional parameter if using the Vonage Sandbox to test Silent Auth integrations. + * + * @return Whether the Vonage Sandbox will be used, or {@code null} if not specified (the default). + * + * @since 7.10.0 + */ + @JsonProperty("sandbox") + public Boolean getSandbox() { + return sandbox; + } } diff --git a/src/main/java/com/vonage/client/verify2/VerificationRequest.java b/src/main/java/com/vonage/client/verify2/VerificationRequest.java index 06327f2e4..6406fc16d 100644 --- a/src/main/java/com/vonage/client/verify2/VerificationRequest.java +++ b/src/main/java/com/vonage/client/verify2/VerificationRequest.java @@ -317,6 +317,7 @@ public Builder clientRef(String clientRef) { } /** + * (OPTIONAL) * Set this parameter to {@code false} to force through the request even if it's * blocked by the network's fraud protection. Refer to * diff --git a/src/main/java/com/vonage/client/verify2/VerificationResponse.java b/src/main/java/com/vonage/client/verify2/VerificationResponse.java index 9ad779cae..952564b9c 100644 --- a/src/main/java/com/vonage/client/verify2/VerificationResponse.java +++ b/src/main/java/com/vonage/client/verify2/VerificationResponse.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.vonage.client.Jsonable; +import java.net.URI; import java.util.UUID; /** @@ -26,6 +27,7 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class VerificationResponse implements Jsonable { protected UUID requestId; + protected URI checkUrl; /** * Protected to prevent users from explicitly creating this object. @@ -43,9 +45,21 @@ public UUID getRequestId() { return requestId; } + /** + * URL for Silent Auth Verify workflow completion (only present if using Silent Auth). + * + * @return The URL to check for Silent Authentication, or {@code null} if not applicable. + * + * @since 7.10.0 + */ + @JsonProperty("check_url") + public URI getCheckUrl() { + return checkUrl; + } + @Override public String toString() { - return getClass().getSimpleName()+" {requestId='"+requestId+"'}"; + return getClass().getSimpleName() + "{requestId=" + requestId + ", checkUrl=" + checkUrl + '}'; } /** diff --git a/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java b/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java index 7e9756060..e93661c56 100644 --- a/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java +++ b/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java @@ -24,6 +24,7 @@ import java.util.Collections; public class VerificationRequestTest { + static final boolean SANDBOX = true; static final Locale LOCALE = Locale.PORTUGUESE_PORTUGAL; static final int CODE_LENGTH = 8, CHANNEL_TIMEOUT = 120; static final String @@ -64,6 +65,8 @@ Workflow getWorkflowRequiredParamsForChannel(Channel channel) { Workflow getWorkflowAllParamsForChannel(Channel channel) { switch (channel) { + case SILENT_AUTH: + return new SilentAuthWorkflow(TO_NUMBER, SANDBOX); case SMS: return new SmsWorkflow(TO_NUMBER, APP_HASH); case WHATSAPP: @@ -96,22 +99,30 @@ String getExpectedRequiredParamsForSingleWorkflowJson(Channel channel) { String getExpectedAllParamsForSingleWorkflowJson(Channel channel) { String expectedJson = getExpectedRequiredParamsForSingleWorkflowJson(channel), prefix, replacement; + if (channel == Channel.SMS) { - prefix = TO_NUMBER + "\""; + prefix = TO_NUMBER + '"'; replacement = prefix + ",\"app_hash\":\""+APP_HASH+"\""; expectedJson = expectedJson.replace(prefix, replacement); } if (channel == Channel.WHATSAPP) { - prefix = TO_NUMBER + "\""; + prefix = TO_NUMBER + '"'; replacement = prefix + ",\"from\":\""+FROM_NUMBER+"\""; expectedJson = expectedJson.replace(prefix, replacement); } if (channel == Channel.EMAIL) { - prefix = TO_EMAIL + "\""; + prefix = TO_EMAIL + '"'; replacement = prefix + ",\"from\":\""+FROM_EMAIL+"\""; expectedJson = expectedJson.replace(prefix, replacement); } + if (channel == Channel.SILENT_AUTH) { + prefix = TO_NUMBER + '"'; + replacement = prefix + ",\"sandbox\":" + SANDBOX; + expectedJson = expectedJson.replace(prefix, replacement); + } + prefix = "{\"locale\":\"pt-pt\",\"channel_timeout\":"+ CHANNEL_TIMEOUT; + if (channel != Channel.SILENT_AUTH && channel != Channel.WHATSAPP_INTERACTIVE) { prefix += ",\"code_length\":"+CODE_LENGTH; } diff --git a/src/test/java/com/vonage/client/verify2/VerificationResponseTest.java b/src/test/java/com/vonage/client/verify2/VerificationResponseTest.java index 49717e218..02bf0845c 100644 --- a/src/test/java/com/vonage/client/verify2/VerificationResponseTest.java +++ b/src/test/java/com/vonage/client/verify2/VerificationResponseTest.java @@ -16,8 +16,9 @@ package com.vonage.client.verify2; import com.vonage.client.VonageResponseParseException; -import org.junit.jupiter.api.*; import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.*; +import java.net.URI; import java.util.UUID; public class VerificationResponseTest { @@ -25,8 +26,12 @@ public class VerificationResponseTest { @Test public void testConstructFromValidJson() { UUID rqid = UUID.randomUUID(); - VerificationResponse response = VerificationResponse.fromJson("{\"request_id\":\""+rqid+"\"}"); + String checkUrl = "https://example.com/v2/"+rqid+"/silent-auth/redirect"; + VerificationResponse response = VerificationResponse.fromJson( + "{\"request_id\":\""+rqid+"\",\"check_url\":\""+checkUrl+"\"}" + ); assertEquals(rqid, response.getRequestId()); + assertEquals(URI.create(checkUrl), response.getCheckUrl()); String toString = response.toString(); assertTrue(toString.contains("VerificationResponse")); assertTrue(toString.contains(rqid.toString())); diff --git a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java index 31337590a..bc97fc3b3 100644 --- a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java +++ b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java @@ -50,7 +50,7 @@ VerificationRequest newVerificationRequestWithAllParamsAndWorkflows() { String toNumber = "447100000009", fromNumber = "447900000001", toEmail = "email@domain.tld", fromEmail = "hello@example.com"; List workflows = Arrays.asList( - new SilentAuthWorkflow(toNumber), + new SilentAuthWorkflow(toNumber, true), new SmsWorkflow(toNumber), new EmailWorkflow(toEmail, fromEmail), new VoiceWorkflow(toNumber), @@ -71,6 +71,7 @@ void stubSuccessfulVerifyUserResponseAndRun(VerificationRequest request) throws VerificationResponse response = client.sendVerification(request); assertNotNull(response); assertEquals(REQUEST_ID, response.getRequestId()); + assertNull(response.getCheckUrl()); } @Test