Exchange an authorization code or refresh token for an access token
const url = 'https://dev-api.infiniteaudience.ai/v1/oauth/token';const options = { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, body: new URLSearchParams({ grant_type: 'authorization_code', code: 'example', redirect_uri: 'https://example.com', code_verifier: 'example', client_id: 'example', client_secret: 'example' })};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://dev-api.infiniteaudience.ai/v1/oauth/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data grant_type=authorization_code \ --data code=example \ --data redirect_uri=https://example.com \ --data code_verifier=example \ --data client_id=example \ --data client_secret=exampleClient-authenticated (RFC 6749 §3.2), not user-authenticated. Accepts application/x-www-form-urlencoded or application/json. Send your client_id/client_secret via HTTP Basic (Authorization: Basic base64(client_id:client_secret)) or as body fields.
grant_type=authorization_code requires code, the exact same redirect_uri you sent to /authorize, and code_verifier (the PKCE secret whose SHA-256 hash matches the code_challenge you sent to /authorize).
grant_type=refresh_token requires refresh_token and rotates it — store the refresh_token returned in the response and discard the one you presented; it is now rejected if presented again.
Request Bodyrequired
Section titled “Request Bodyrequired”object
RFC 7636 PKCE verifier — must hash (S256) to the code_challenge you sent to /authorize.
object
object
RFC 7636 PKCE verifier — must hash (S256) to the code_challenge you sent to /authorize.
object
Responses
Section titled “Responses”A fresh access token and a rotated refresh token, for either grant type.
object
Opaque bearer token. Use exactly like an API-key-derived one: Authorization: Bearer <access_token>.
Seconds until the access token expires (1800).
Supersedes any previously-issued refresh token for this connection — the old one is now rejected.
Space-delimited granted scopes.
Example
{ "token_type": "Bearer"}RFC 6749-shaped OAuth protocol error — error is a fixed machine-readable code and error_description is a human-readable detail. Deliberately NOT this API’s usual {error, code, message} shape — this is the RFC’s own error contract, used only by /v1/oauth/authorize, /v1/oauth/token, and /v1/oauth/revoke.
RFC 6749 §5.2 / §4.1.2.1 error body — see the OAuthError response component.
object
Example
{ "error": "invalid_request"}RFC 6749-shaped OAuth protocol error — error is a fixed machine-readable code and error_description is a human-readable detail. Deliberately NOT this API’s usual {error, code, message} shape — this is the RFC’s own error contract, used only by /v1/oauth/authorize, /v1/oauth/token, and /v1/oauth/revoke.
RFC 6749 §5.2 / §4.1.2.1 error body — see the OAuthError response component.
object
Example
{ "error": "invalid_request"}