Get a temporary request token
POST
https://api.testingapis.com/api/auth/oauth1/request_tokenGet a temporary request token (step 1 of the three-legged flow).
Sign with the consumer credentials only; sending an oauth_token is rejected. oauth_callback is required: an http(s) URL, or oob to have the verifier shown instead of redirected. In Postman, leave the token fields empty and fill in Callback URL under Advanced.
Response: application/x-www-form-urlencoded by default, or JSON when the request sends Accept: application/json. The request token expires after 10 minutes. Next: open GET /api/auth/oauth1/authorize?oauth_token=<request token>.
OAuth 1.0a signature with the consumer credentials only: apibee-consumer-key / apibee-consumer-secret
Parameters 8
| Name | Type | Description |
|---|---|---|
oauth_consumer_keyrequired | header · string | apibee-consumer-key. In the Authorization: OAuth header, the query string or a form body (one place only). |
oauth_callbackrequired | header · string | An absolute http(s) URL to redirect to after authorization, or oob to get the verifier as JSON. |
oauth_signature_methodrequired | header · string | HMAC-SHA1, HMAC-SHA256, HMAC-SHA512 or PLAINTEXT. |
oauth_signaturerequired | header · string | Signed with the consumer secret only: the signing key is consumer_secret& (empty token secret). For PLAINTEXT, send apibee-consumer-secret%26. |
oauth_timestamp | header · string | Unix time in seconds, within 5 minutes of server time. Required for the HMAC methods; may be left out for PLAINTEXT. |
oauth_nonce | header · string | A random string; each one works once. Required for the HMAC methods; may be left out for PLAINTEXT. |
oauth_version | header · string | Optional. If sent, it must be 1.0. |
Accept | header · string | application/json for a JSON response. Without it the response is application/x-www-form-urlencoded. |
Responses
- 200
- oauth_token, oauth_token_secret, oauth_callback_confirmed=true and oauth_expires_in (600).
- 400
- parameter_absent (no oauth_callback), parameter_rejected (a bad callback, or an oauth_token was sent), or another protocol parameter problem.
- 401
- consumer_key_unknown, timestamp_refused, nonce_used or signature_invalid.
Example
Request
curl -X POST "https://api.testingapis.com/api/auth/oauth1/request_token" \
-H "Accept: application/json" \
-H 'Authorization: OAuth oauth_consumer_key="apibee-consumer-key", oauth_signature_method="PLAINTEXT", oauth_callback="oob", oauth_signature="apibee-consumer-secret%26"'Response200 OK
{
"oauth_token": "o1rt_6112c483e357a56ceb9ea6d5fc7bc9e31e89b4ae",
"oauth_token_secret": "o1rs_e2e13614310bf304d0cec178961363cc9928cb74",
"oauth_callback_confirmed": "true",
"oauth_expires_in": "600"
}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/auth/oauth1/request_token", {
method: "POST",
headers: {
"Accept": "application/json",
"Authorization": "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_signature_method=\"PLAINTEXT\", oauth_callback=\"oob\", oauth_signature=\"apibee-consumer-secret%26\"",
},
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"POST",
"https://api.testingapis.com/api/auth/oauth1/request_token",
headers={
"Accept": "application/json",
"Authorization": "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_signature_method=\"PLAINTEXT\", oauth_callback=\"oob\", oauth_signature=\"apibee-consumer-secret%26\"",
},
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/oauth1/request_token"))
.header("Accept", "application/json")
.header("Authorization", "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_signature_method=\"PLAINTEXT\", oauth_callback=\"oob\", oauth_signature=\"apibee-consumer-secret%26\"")
.method("POST", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}