Send a form to a protected resource with an OAuth 1.0a signed request
POST
https://api.testingapis.com/api/auth/oauth1Same credentials and rules as GET /api/auth/oauth1. Fields of an application/x-www-form-urlencoded body are part of the signature; other body types are not signed. The OAuth parameters may go in the form body instead of the Authorization header, but not in both.
OAuth 1.0a signature: consumer apibee-consumer-key / apibee-consumer-secret, plus token apibee-access-token / apibee-token-secret, one from POST /api/auth/oauth1/access_token, or no token (two-legged)
Parameters 7
| 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_token | header · string | apibee-access-token, an access token from POST /api/auth/oauth1/access_token, or left out for a two-legged request. |
oauth_signature_methodrequired | header · string | HMAC-SHA1, HMAC-SHA256, HMAC-SHA512 or PLAINTEXT. |
oauth_signaturerequired | header · string | Base64 HMAC of the signature base string, or for PLAINTEXT the signing key itself: consumer_secret&token_secret, percent-encoded (& becomes %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. |
Request body
Optional. application/x-www-form-urlencoded. Any form fields; they are covered by the OAuth signature.
Example body
status=helloResponses
- 200
- Signature valid. Same body as GET /api/auth/oauth1.
- 400
- parameter_absent (a required OAuth parameter is missing), parameter_rejected (a parameter is duplicated or OAuth parameters are in more than one place), version_rejected or signature_method_rejected.
- 401
- consumer_key_unknown, token_rejected, token_expired, timestamp_refused, nonce_used or signature_invalid. Carries WWW-Authenticate: OAuth realm="apibee", oauth_problem="...".
Example
Request
curl -X POST "https://api.testingapis.com/api/auth/oauth1" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H 'Authorization: OAuth oauth_consumer_key="apibee-consumer-key", oauth_token="apibee-access-token", oauth_signature_method="PLAINTEXT", oauth_signature="apibee-consumer-secret%26apibee-token-secret"' \
-d 'status=hello'Response200 OK
{
"authenticated": true,
"scheme": "oauth1",
"legs": "three-legged",
"signatureMethod": "PLAINTEXT",
"parametersIn": "Authorization header",
"consumerKey": "apibee-consumer-key",
"token": "apibee-access-token",
"tokenExpiresIn": null,
"user": {
"username": "apibee",
"name": "TestingAPIs Tester",
"email": "tester@example.com"
},
"timestamp": null,
"nonce": null,
"signatureBaseString": null
}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/auth/oauth1", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_token=\"apibee-access-token\", oauth_signature_method=\"PLAINTEXT\", oauth_signature=\"apibee-consumer-secret%26apibee-token-secret\"",
},
body: "status=hello",
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"POST",
"https://api.testingapis.com/api/auth/oauth1",
headers={
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_token=\"apibee-access-token\", oauth_signature_method=\"PLAINTEXT\", oauth_signature=\"apibee-consumer-secret%26apibee-token-secret\"",
},
data="status=hello".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/oauth1"))
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Authorization", "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_token=\"apibee-access-token\", oauth_signature_method=\"PLAINTEXT\", oauth_signature=\"apibee-consumer-secret%26apibee-token-secret\"")
.method("POST", HttpRequest.BodyPublishers.ofString("status=hello"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}