package hello.world;
import java.lang.Exception;
import org.openapis.openapi.AriesJava;
import org.openapis.openapi.models.errors.ErrorResponse;
import org.openapis.openapi.models.operations.*;
public class Application {
public static void main(String[] args) throws ErrorResponse, Exception {
AriesJava sdk = AriesJava.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
Oauth2TokenRequest req = Oauth2TokenRequest.builder()
.grantType(GrantType.AUTHORIZATION_CODE)
.clientId("client_abc123xyz")
.code("auth_code_abc123xyz789def456")
.clientSecret("secret_xyz789abc")
.redirectUri("https://yourapp.com/callback")
.build();
Oauth2TokenResponse res = sdk.oauth2().token()
.request(req)
.call();
if (res.object().isPresent()) {
// handle response
}
}
}curl --request POST \
--url https://api.tradearies.dev/v1/oauth2/token \
--header 'Content-Type: application/json' \
--data '
{
"grant_type": "authorization_code",
"code": "auth_code_abc123xyz789def456",
"client_id": "client_abc123xyz",
"client_secret": "secret_xyz789abc",
"redirect_uri": "https://yourapp.com/callback"
}
'import requests
url = "https://api.tradearies.dev/v1/oauth2/token"
payload = {
"grant_type": "authorization_code",
"code": "auth_code_abc123xyz789def456",
"client_id": "client_abc123xyz",
"client_secret": "secret_xyz789abc",
"redirect_uri": "https://yourapp.com/callback"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
grant_type: 'authorization_code',
code: 'auth_code_abc123xyz789def456',
client_id: 'client_abc123xyz',
client_secret: 'secret_xyz789abc',
redirect_uri: 'https://yourapp.com/callback'
})
};
fetch('https://api.tradearies.dev/v1/oauth2/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tradearies.dev/v1/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'grant_type' => 'authorization_code',
'code' => 'auth_code_abc123xyz789def456',
'client_id' => 'client_abc123xyz',
'client_secret' => 'secret_xyz789abc',
'redirect_uri' => 'https://yourapp.com/callback'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.tradearies.dev/v1/oauth2/token"
payload := strings.NewReader("{\n \"grant_type\": \"authorization_code\",\n \"code\": \"auth_code_abc123xyz789def456\",\n \"client_id\": \"client_abc123xyz\",\n \"client_secret\": \"secret_xyz789abc\",\n \"redirect_uri\": \"https://yourapp.com/callback\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.tradearies.dev/v1/oauth2/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"grant_type\": \"authorization_code\",\n \"code\": \"auth_code_abc123xyz789def456\",\n \"client_id\": \"client_abc123xyz\",\n \"client_secret\": \"secret_xyz789abc\",\n \"redirect_uri\": \"https://yourapp.com/callback\"\n}"
response = http.request(request)
puts response.read_body{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.cThIIoDvwdueQB468K5xDc5633seEFoqwxjF_xSJyQQ",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token_expires_in": 2592000,
"scope": "read write"
}OAuth2 Token
Exchanges authorization code for access and refresh tokens, or refreshes tokens. This endpoint serves two purposes: 1) Authorization Code Grant - exchanges authorization code for tokens (supports both traditional flow with client_secret and PKCE flow with code_verifier), 2) Refresh Token Grant - exchanges refresh token for new access token.
package hello.world;
import java.lang.Exception;
import org.openapis.openapi.AriesJava;
import org.openapis.openapi.models.errors.ErrorResponse;
import org.openapis.openapi.models.operations.*;
public class Application {
public static void main(String[] args) throws ErrorResponse, Exception {
AriesJava sdk = AriesJava.builder()
.bearerAuth(System.getenv().getOrDefault("BEARER_AUTH", ""))
.build();
Oauth2TokenRequest req = Oauth2TokenRequest.builder()
.grantType(GrantType.AUTHORIZATION_CODE)
.clientId("client_abc123xyz")
.code("auth_code_abc123xyz789def456")
.clientSecret("secret_xyz789abc")
.redirectUri("https://yourapp.com/callback")
.build();
Oauth2TokenResponse res = sdk.oauth2().token()
.request(req)
.call();
if (res.object().isPresent()) {
// handle response
}
}
}curl --request POST \
--url https://api.tradearies.dev/v1/oauth2/token \
--header 'Content-Type: application/json' \
--data '
{
"grant_type": "authorization_code",
"code": "auth_code_abc123xyz789def456",
"client_id": "client_abc123xyz",
"client_secret": "secret_xyz789abc",
"redirect_uri": "https://yourapp.com/callback"
}
'import requests
url = "https://api.tradearies.dev/v1/oauth2/token"
payload = {
"grant_type": "authorization_code",
"code": "auth_code_abc123xyz789def456",
"client_id": "client_abc123xyz",
"client_secret": "secret_xyz789abc",
"redirect_uri": "https://yourapp.com/callback"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
grant_type: 'authorization_code',
code: 'auth_code_abc123xyz789def456',
client_id: 'client_abc123xyz',
client_secret: 'secret_xyz789abc',
redirect_uri: 'https://yourapp.com/callback'
})
};
fetch('https://api.tradearies.dev/v1/oauth2/token', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.tradearies.dev/v1/oauth2/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'grant_type' => 'authorization_code',
'code' => 'auth_code_abc123xyz789def456',
'client_id' => 'client_abc123xyz',
'client_secret' => 'secret_xyz789abc',
'redirect_uri' => 'https://yourapp.com/callback'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.tradearies.dev/v1/oauth2/token"
payload := strings.NewReader("{\n \"grant_type\": \"authorization_code\",\n \"code\": \"auth_code_abc123xyz789def456\",\n \"client_id\": \"client_abc123xyz\",\n \"client_secret\": \"secret_xyz789abc\",\n \"redirect_uri\": \"https://yourapp.com/callback\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}require 'uri'
require 'net/http'
url = URI("https://api.tradearies.dev/v1/oauth2/token")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"grant_type\": \"authorization_code\",\n \"code\": \"auth_code_abc123xyz789def456\",\n \"client_id\": \"client_abc123xyz\",\n \"client_secret\": \"secret_xyz789abc\",\n \"redirect_uri\": \"https://yourapp.com/callback\"\n}"
response = http.request(request)
puts response.read_body{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.cThIIoDvwdueQB468K5xDc5633seEFoqwxjF_xSJyQQ",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token_expires_in": 2592000,
"scope": "read write"
}Body
OAuth2 grant type
authorization_code, refresh_token OAuth2 client identifier
Authorization code from /v1/oauth2/authorize/confirm (required for authorization_code grant)
Client secret (required for confidential clients and refresh_token grant)
PKCE code verifier (required for PKCE flow, replaces client_secret)
Redirect URI (required for authorization_code grant, must match authorization request)
Refresh token (required for refresh_token grant)
Response
Tokens generated successfully
Bearer token for API authentication
Token type (always Bearer)
Bearer Access token expiration time in seconds (typically 3600 = 1 hour)
Token to refresh the access token
Refresh token expiration time in seconds (typically 2592000 = 30 days)
Space-separated list of granted scopes
Was this page helpful?