Exchange an authorized request token for an access token
https://api.testingapis.com/api/auth/oauth1/access_tokenExchange an authorized request token for an access token (step 3 of the three-legged flow).
Sign with apibee-consumer-key / apibee-consumer-secret plus the request token from POST /api/auth/oauth1/request_token and its secret, and include oauth_verifier from GET /api/auth/oauth1/authorize. In Postman, put the request token and secret in Access Token and Token Secret, and the verifier in Verifier.
Response: application/x-www-form-urlencoded by default, or JSON when the request sends Accept: application/json. The access token works on /api/auth/oauth1 for 1 hour. Each request token can be exchanged only once.
OAuth 1.0a signature with the consumer credentials plus the request token and its secret
Parameters 9
| 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_tokenrequired | header · string | The request token from POST /api/auth/oauth1/request_token. |
oauth_verifierrequired | header · string | The verifier from GET /api/auth/oauth1/authorize. |
oauth_signature_methodrequired | header · string | HMAC-SHA1, HMAC-SHA256, HMAC-SHA512 or PLAINTEXT. |
oauth_signaturerequired | header · string | Signed with the request token's secret: the signing key is consumer_secret&request_token_secret. For PLAINTEXT, send that key 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. |
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, username and oauth_expires_in (3600).
- 400
- parameter_absent: oauth_token or oauth_verifier is missing. Or another protocol parameter problem.
- 401
- permission_unknown (not authorized yet), parameter_rejected (wrong verifier), token_used, token_expired, token_rejected, or a signature problem.
Example
curl -X POST "https://api.testingapis.com/api/auth/oauth1/access_token" \
-H "Accept: application/json" \
-H 'Authorization: OAuth oauth_consumer_key="apibee-consumer-key", oauth_token="{{oauth1RequestToken}}", oauth_verifier="{{oauth1Verifier}}", oauth_signature_method="PLAINTEXT", oauth_signature="apibee-consumer-secret%26{{oauth1RequestSecret}}"'{
"oauth_token": "o1at_beca6b87b958050a30c6e3a3964c430afaaa2c32",
"oauth_token_secret": "o1as_4323dfe2ab31282bd2b69f07bee972b14a71ffd8",
"username": "apibee",
"oauth_expires_in": "3600"
}Code examples
const response = await fetch("https://api.testingapis.com/api/auth/oauth1/access_token", {
method: "POST",
headers: {
"Accept": "application/json",
"Authorization": "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_token=\"{{oauth1RequestToken}}\", oauth_verifier=\"{{oauth1Verifier}}\", oauth_signature_method=\"PLAINTEXT\", oauth_signature=\"apibee-consumer-secret%26{{oauth1RequestSecret}}\"",
},
});
console.log(response.status, await response.text());import requests
response = requests.request(
"POST",
"https://api.testingapis.com/api/auth/oauth1/access_token",
headers={
"Accept": "application/json",
"Authorization": "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_token=\"{{oauth1RequestToken}}\", oauth_verifier=\"{{oauth1Verifier}}\", oauth_signature_method=\"PLAINTEXT\", oauth_signature=\"apibee-consumer-secret%26{{oauth1RequestSecret}}\"",
},
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/access_token"))
.header("Accept", "application/json")
.header("Authorization", "OAuth oauth_consumer_key=\"apibee-consumer-key\", oauth_token=\"{{oauth1RequestToken}}\", oauth_verifier=\"{{oauth1Verifier}}\", oauth_signature_method=\"PLAINTEXT\", oauth_signature=\"apibee-consumer-secret%26{{oauth1RequestSecret}}\"")
.method("POST", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}