New in 2.4: Test runs you can trust See what's new →

Verify an HMAC-SHA256 request signature

POSThttps://api.testingapis.com/api/auth/hmac

Headers:

X-Timestamp: current Unix time in seconds; must be within 300 seconds of server time. X-Signature: lowercase hex of HMAC-SHA256(key: "apibee-hmac-secret", message: X-Timestamp + "." + raw request body). An optional sha256= prefix is accepted. Bash: SIG=$(printf '%s' "$TS.$BODY" | openssl dgst -sha256 -hmac apibee-hmac-secret | awk '{print $NF}')

Note: X-Signature = hex(HMAC-SHA256("apibee-hmac-secret", X-Timestamp + "." + rawBody)); timestamp must be within 5 minutes. Each signature is accepted once: the identical request sent again within the 5-minute window gets 401 (replay refused).

HMAC-SHA256 request signature (X-Timestamp + X-Signature), secret apibee-hmac-secret

Parameters 2

NameTypeDescription
X-Timestamprequiredheader · stringUnix time in seconds; must be within 5 minutes of the server clock.
X-Signaturerequiredheader · stringHex HMAC-SHA256 of "{X-Timestamp}.{raw body}" with secret apibee-hmac-secret (optional sha256= prefix).

Request body

Optional. application/json. Any body; it is covered by X-Signature.

Example body
{"event":"ping"}

Responses

200
Signature valid.
401
Headers missing, timestamp not numeric or outside the tolerance, signature mismatch, or a replayed signature.

Example

Request
curl -X POST "https://api.testingapis.com/api/auth/hmac" \
  -H "Content-Type: application/json" \
  -H "X-Timestamp: {{unixTimestamp}}" \
  -H "X-Signature: {{hmacSignature}}" \
  -d '{"event":"ping"}'
Run in Studio
Response200 OK
{"authenticated": true, "scheme": "hmac-sha256", "timestamp": 1790792796, "bodyLength": 16}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/auth/hmac", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Timestamp": "{{unixTimestamp}}",
    "X-Signature": "{{hmacSignature}}",
  },
  body: "{\"event\":\"ping\"}",
});
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "POST",
    "https://api.testingapis.com/api/auth/hmac",
    headers={
        "Content-Type": "application/json",
        "X-Timestamp": "{{unixTimestamp}}",
        "X-Signature": "{{hmacSignature}}",
    },
    data="{\"event\":\"ping\"}".encode("utf-8"),
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/auth/hmac"))
            .header("Content-Type", "application/json")
            .header("X-Timestamp", "{{unixTimestamp}}")
            .header("X-Signature", "{{hmacSignature}}")
            .method("POST", HttpRequest.BodyPublishers.ofString("{\"event\":\"ping\"}"))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}