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

Exchange an authorized request token for an access token

POSThttps://api.testingapis.com/api/auth/oauth1/access_token

Exchange 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

NameTypeDescription
oauth_consumer_keyrequiredheader · stringapibee-consumer-key. In the Authorization: OAuth header, the query string or a form body (one place only).
oauth_tokenrequiredheader · stringThe request token from POST /api/auth/oauth1/request_token.
oauth_verifierrequiredheader · stringThe verifier from GET /api/auth/oauth1/authorize.
oauth_signature_methodrequiredheader · stringHMAC-SHA1, HMAC-SHA256, HMAC-SHA512 or PLAINTEXT.
oauth_signaturerequiredheader · stringSigned 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_timestampheader · stringUnix time in seconds, within 5 minutes of server time. Required for the HMAC methods; may be left out for PLAINTEXT.
oauth_nonceheader · stringA random string; each one works once. Required for the HMAC methods; may be left out for PLAINTEXT.
oauth_versionheader · stringOptional. If sent, it must be 1.0.
Acceptheader · stringapplication/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

Request
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}}"'
Run in Studio
Response200 OK
{
  "oauth_token": "o1at_beca6b87b958050a30c6e3a3964c430afaaa2c32",
  "oauth_token_secret": "o1as_4323dfe2ab31282bd2b69f07bee972b14a71ffd8",
  "username": "apibee",
  "oauth_expires_in": "3600"
}

Code examples

JavaScript (fetch)
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());
Python (requests)
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)
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/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());
    }
}