Getting 'Missing request timestamp' error from DUO API: Code 40104

1.2k Views Asked by At

Can anyone help with me with this error I am facing? I am fairly new to java. Here I am trying to create a user on Duo Admin API but when I run this code I get this

    import java.io.IOException;
    import java.net.URI;
    import java.net.http.HttpClient;
    import java.net.http.HttpRequest;
    import java.net.http.HttpResponse;
    import java.util.Base64;
    
    // HTTP basic authentication example in Java using the RTC Server RESTful API
    public class Untitled {
    
        public static void main(String[] args) throws IOException, InterruptedException {
    
            // Customer ID
            final String customerKey = "key";
            // Customer secret
            final String customerSecret = "secret";
    
            // Concatenate customer key and customer secret and use base64 to encode the
            // concatenated string
            String plainCredentials = customerKey + ":" + customerSecret;
            String base64Credentials = new String(Base64.getEncoder().encode(plainCredentials.getBytes()));
            // Create authorization header
            String authorizationHeader = "Basic " + base64Credentials;
    
            HttpClient client = HttpClient.newHttpClient();
    
            // Create HTTP request object
            HttpRequest request = HttpRequest.newBuilder()
                    .uri(URI.create("https://api-e9770554.duosecurity.com/admin/v1/users")).GET()
                    .header("Authorization", authorizationHeader).header("Content-Type", "application/json").build();
            // Send HTTP request
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    
            System.out.println(response.body());
        }
    }

ERROR

{"code": 40104, "message": "Missing request timestamp", "stat": "FAIL"}
1

There are 1 best solutions below

1
On BEST ANSWER

This has nothing to do with Java, but rather with the duosecurity.com API. Obviously some required data (request timestamp) is missing.

Duo Help page states:

40104 Missing request timestamp
EXPLANATION: A Date or X-Duo-Date header was missing or formatted incorrectly.
RESOLUTION: Ensure that the Date or X-Duo-Date header exists and is formatted correctly.

so you should add something like

.header("X-Duo-Date", "Tue, 17 Aug 2021 12:24:26 -0000") 

(Note: date is in RFC 2822 format)