Search code examples
javamavenintellij-ideatwo-factor-authenticationvonage

Nexmo 2FA is not working/ is bugged, dependency doesn't include some methods needed for recieving the code and verifying it


The tutorial showed at https://dashboard.nexmo.com/getting-started/verify says that everything should work by coding:

1   NexmoClient client = NexmoClient.Builder()
2     .apiKey("HIDDEN-CODE-I-CANNOT-SHOW")
3     .apiSecret("HIDDEN-CODE-I-CANNOT-SHOW")
4     .build();
5   VerifyClient verifyClient = client.getVerifyClient();
6
7   VerifyRequest request = new VerifyRequest("HIDDEN-CODE-I-CANNOT-SHOW", "HIDDEN-CODE-I-CANNOT-SHOW");
8   request.setLength(4);
9   
10   VerifyResponse response = verifyClient.verify(request);
11
12   if (response.getStatus() == VerifyStatus.OK) {
13       System.out.printf("RequestID: %s", response.getRequestId());
14   } else {
15       System.out.printf("ERROR! %s: %s",
16         response.getStatus(),
17         response.getErrorText()
18       );
19   }

My problem/bug is the next:

request.SETLENGHT(4);
response.GETSTATUS();

These two lines of code (8-12) are red (the caracters that are in capital letters only). If i leave my cursor on them it displays a message "Cannot resolve symbol 'setLength'" and "Cannot resolve symbol 'getStatus'" respectively.

I tought somebody had the same problem as i did, but it wasn't the case. I have entered the repository of the developer of the nexmo library and the two functions are written on there (I'm trying to say that they exist), but in my program they weren't founded.

These are the repositories of the developers:

  1. https://github.com/Nexmo/nexmo-java
  2. https://github.com/Nexmo/nexmo-java/blob/master/src/main/java/com/nexmo/client/verify/VerifyRequest.java
  3. https://github.com/vonage/vonage-java-sdk

In the first one they say and i quote "We recommend users begin migrating over to the Vonage Java Server SDK. If you have any questions, feel free to reach out to us at [email protected] or through our Community Slack at https://developer.nexmo.com/community/slack" As they said i did try to migrate to the new version of the project but the problem of that two lines preserves there too.

The second link shows some funtions written for the nexmo library. From the line 315 to the line 323 you can see that the function ".setLenght" does exist because the developers created a builder for it, here is the code copied and pasted from that link:

    /**
     * @param length (optional) The length of the verification code to be sent to the user. Must be either 4 or 6. Use
     *               -1 to use the default value.
     * @return {@link Builder}
     */
    public Builder length(Integer length) {
        this.length = length;
        return this;
    }

What could be the problem? Libraries? Compatibility? I am using Apache Maven 3.6.3. This is my pom:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.4.2</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.2FA</groupId>
        <artifactId>Auth-Two-Steps</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>Auth-Two-Steps</name>
        <description>Mini project to learn authentication</description>
        <properties>
            <java.version>11</java.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>com.nexmo</groupId>
                <artifactId>client</artifactId>
                <version>5.6.0</version>
            </dependency>
    
    
            <dependency>
                <groupId>com.2FA</groupId>
                <artifactId>Auth-Two-Steps</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

Solution

  • Those snippets would work on the nexmo 4.x SDK but will fail on the 5.x Nexmo SDK and 6.x Vonage SDK, it needs to be updated. See the code snippet - that will show you how to manage everything. setLength looks like it was removed when the builder pattern was added to Verify Request, you should use the builder pattern instead

    e.g.

    VerifyRequest request = VerifyRequest.builder("12018675309","acme").length(6).build();
    

    getStatus() looks like it ought to work - if you continue to have problems you may want to make sure it's getting imported.