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

Start the authorization code flow and issue a code

GEThttps://api.testingapis.com/api/auth/oauth/authorize

Start the authorization code flow and issue a code (auto-approved as user apibee).

Codes are single use and expire after 10 minutes. Exchange them at POST /api/auth/oauth/token.

Note: PKCE: code_challenge = base64url(SHA-256(code_verifier)). Registered redirect URIs (localhost, 127.0.0.1, Postman, this server's Swagger) get a 302. Any other redirect_uri is refused with 400 invalid_request and no code is issued. Leave redirect_uri out to get the code as JSON.

Parameters 7

NameTypeDescription
response_typequery · stringMust be code.
client_idquery · stringapibee-client (confidential) or apibee-public (public; PKCE required).
redirect_uriquery · stringWhere to send the code. Registered: http(s) URIs on localhost or 127.0.0.1 (any port) and the Postman callbacks. Any other value is refused with 400 and no code is issued; leave it out to get the code as JSON.
scopequery · stringSpace-separated subset of the client's scopes (apibee-client: read write profile email; apibee-public: read profile email). Defaults to all of them.
statequery · stringOpaque value echoed back unchanged.
code_challengequery · stringPKCE challenge: BASE64URL(SHA256(code_verifier)) for S256, or the verifier itself for plain.
code_challenge_methodquery · stringS256 or plain (default plain).

Responses

200
Code returned as JSON (no redirect_uri sent).
302
Redirect to redirect_uri with code and state.
400
invalid_client, unsupported_response_type, invalid_request (including an unregistered redirect_uri) or invalid_scope.

Example

Request
curl -X GET "https://api.testingapis.com/api/auth/oauth/authorize?response_type=code&client_id=apibee-public&redirect_uri=http://localhost:3000/callback&state=xyz&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256"
Run in Studio
Response302 Found
Location: http://localhost:3000/callback?code=code_3d7eac7eaf6981c2de11965a88d969531cf9a9c3&state=xyz

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/auth/oauth/authorize?response_type=code&client_id=apibee-public&redirect_uri=http://localhost:3000/callback&state=xyz&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256");
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "GET",
    "https://api.testingapis.com/api/auth/oauth/authorize?response_type=code&client_id=apibee-public&redirect_uri=http://localhost:3000/callback&state=xyz&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256",
    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/oauth/authorize?response_type=code&client_id=apibee-public&redirect_uri=http://localhost:3000/callback&state=xyz&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}