Call a protected resource with an OAuth 1.0a signed request
https://api.testingapis.com/api/auth/oauth1Accepts the static token apibee-access-token / apibee-token-secret (never expires; user apibee), a token issued by POST /api/auth/oauth1/access_token, or no token at all for a two-legged (consumer-only) request. A request token is rejected: exchange it first. Query parameters are covered by the signature.
Signing key: percentEncode(consumer_secret) + "&" + percentEncode(token_secret), with an empty token secret when there is no token. Signature methods: HMAC-SHA1, HMAC-SHA256, HMAC-SHA512 and PLAINTEXT; RSA-SHA1 is not supported. The rules for every signed request, and what each oauth_problem means, are under Signing rules on the OAuth 1.0a page.
Note: legs is "two-legged" and user is null when no token is sent. tokenExpiresIn is the seconds left for an issued token and null for the static token. signatureBaseString is the string the server signed (null for PLAINTEXT); on a signature mismatch the 401 carries it in details.signatureBaseString, so you can diff it against yours.
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. |
Responses
- 200
- Signature valid. Returns the legs, signature method, where the OAuth parameters were found, the consumer key, token and user.
- 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
curl -X GET "https://api.testingapis.com/api/auth/oauth1" \
-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"'{
"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
const response = await fetch("https://api.testingapis.com/api/auth/oauth1", {
headers: {
"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\"",
},
});
console.log(response.status, await response.text());import requests
response = requests.request(
"GET",
"https://api.testingapis.com/api/auth/oauth1",
headers={
"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\"",
},
allow_redirects=False,
)
print(response.status_code, response.text)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("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("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}