Welcome to our API documentation. This guide will help you integrate with our OAuth 2.0 API.
To use our API, you need to register your application and implement the OAuth 2.0 authorization flow.
Before you can use our API, you need to register your application:
client_id
and client_secret
Our API uses the OAuth 2.0 Authorization Code flow, which involves the following steps:
Direct your users to our authorization endpoint.
The user will be prompted to log in (if not already) and grant permission to your application.
After authorization, the user will be redirected to your specified redirect URI with an authorization code.
Exchange the authorization code for an access token.
Use the access token to make authenticated API requests.
Our API uses OAuth 2.0 authorization to securely authenticate users and applications.
Redirects the user to our authentication page where they can approve access for your application.
Parameter | Type | Required | Description |
---|---|---|---|
client_id |
string | Yes | Your application's client ID |
redirect_uri |
string | Yes | The URI to redirect to after authorization (must match the one registered) |
response_type |
string | Yes | Must be set to code |
GET /api/authorize.php?client_id=YOUR_CLIENT_ID&redirect_uri=https://example.com/callback&response_type=code
Exchanges an authorization code for an access token.
Parameter | Type | Required | Description |
---|---|---|---|
code |
string | Yes | The authorization code received from the authorize endpoint |
client_id |
string | Yes | Your application's client ID |
client_secret |
string | Yes | Your application's client secret |
POST /api/token.php
Content-Type: application/x-www-form-urlencoded
code=AUTHORIZATION_CODE&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET
{
"access_token": "ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600
}
Once you have an access token, you can use it to access our API endpoints.
Returns information about the authenticated user.
Header | Value | Required | Description |
---|---|---|---|
Authorization |
Bearer ACCESS_TOKEN |
Yes | The access token obtained from the token endpoint |
GET /api/userinfo.php
Authorization: Bearer ACCESS_TOKEN
{
"username": "johndoe",
"email": "john@example.com",
"full_name": "John Doe"
}
API errors are returned with appropriate HTTP status codes and a JSON response.
{
"error": "error_code",
"error_description": "Human-readable description"
}
Error Code | HTTP Status | Description |
---|---|---|
invalid_request |
400 | The request is missing required parameters |
invalid_client |
401 | Client authentication failed |
invalid_code |
400 | The authorization code is invalid or expired |
invalid_token |
401 | The access token is invalid or expired |
Our API implements rate limiting to ensure service availability for all users:
When rate limits are exceeded, the API will return a 429 Too Many Requests
status code with headers indicating the rate limit and when you can retry.
<?php
// Step 1: Redirect user to authorization endpoint
$authUrl = 'https://example.com/api/authorize.php?' . http_build_query([
'client_id' => 'YOUR_CLIENT_ID',
'redirect_uri' => 'YOUR_REDIRECT_URI',
'response_type' => 'code'
]);
header("Location: $authUrl");
exit;
// Step 2: Handle the authorization code (on your redirect URI page)
if (isset($_GET['code'])) {
$code = $_GET['code'];
// Step 3: Exchange the code for an access token
$ch = curl_init('https://example.com/api/token.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'code' => $code,
'client_id' => 'YOUR_CLIENT_ID',
'client_secret' => 'YOUR_CLIENT_SECRET'
]));
$response = curl_exec($ch);
curl_close($ch);
$tokenData = json_decode($response, true);
$accessToken = $tokenData['access_token'];
// Step 4: Use the access token to make API requests
$ch = curl_init('https://example.com/api/userinfo.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $accessToken
]);
$userData = curl_exec($ch);
curl_close($ch);
// Process user data
$user = json_decode($userData, true);
echo "Hello, " . $user['username'];
}
?>
// Step 1: Redirect user to authorization endpoint
function authorize() {
const authUrl = 'https://example.com/api/authorize.php?' +
new URLSearchParams({
client_id: 'YOUR_CLIENT_ID',
redirect_uri: 'YOUR_REDIRECT_URI',
response_type: 'code'
});
window.location.href = authUrl;
}
// Step 2: Handle the authorization code (on your redirect URI page)
async function handleRedirect() {
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
if (code) {
// Step 3: Exchange the code for an access token (via your backend)
const tokenResponse = await fetch('/your-backend-endpoint', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ code })
});
const tokenData = await tokenResponse.json();
const accessToken = tokenData.access_token;
// Step 4: Use the access token to make API requests
const userResponse = await fetch('https://example.com/api/userinfo.php', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
const userData = await userResponse.json();
console.log('User data:', userData);
}
}
import requests
from flask import Flask, request, redirect, session
import os
app = Flask(__name__)
app.secret_key = os.urandom(24)
# Configuration
CLIENT_ID = 'YOUR_CLIENT_ID'
CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
REDIRECT_URI = 'YOUR_REDIRECT_URI'
AUTH_URL = 'https://example.com/api/authorize.php'
TOKEN_URL = 'https://example.com/api/token.php'
API_URL = 'https://example.com/api/userinfo.php'
@app.route('/login')
def login():
# Step 1: Redirect user to authorization endpoint
auth_params = {
'client_id': CLIENT_ID,
'redirect_uri': REDIRECT_URI,
'response_type': 'code'
}
auth_url = f"{AUTH_URL}?{'&'.join(f'{k}={v}' for k, v in auth_params.items())}"
return redirect(auth_url)
@app.route('/callback')
def callback():
# Step 2: Handle the authorization code
code = request.args.get('code')
if code:
# Step 3: Exchange the code for an access token
token_data = {
'code': code,
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET
}
token_response = requests.post(TOKEN_URL, data=token_data)
token_json = token_response.json()
if 'access_token' in token_json:
# Store the token in session
session['access_token'] = token_json['access_token']
# Step 4: Use the access token to make API requests
return redirect('/profile')
return "Authorization failed", 400
@app.route('/profile')
def profile():
# Check if user is authenticated
if 'access_token' not in session:
return redirect('/login')
# Make API request to get user info
headers = {
'Authorization': f"Bearer {session['access_token']}"
}
response = requests.get(API_URL, headers=headers)
if response.status_code == 200:
user_data = response.json()
return f"Hello, {user_data['username']}! Your email is {user_data['email']}"
else:
session.pop('access_token', None)
return redirect('/login')
if __name__ == '__main__':
app.run(debug=True)
If you need help with our API or have any questions, please contact our developer support team:
Our support team is available Monday through Friday, 9 AM to 5 PM (UTC).
Subscribe to our developer newsletter to receive updates about new features, deprecations, and best practices.
Subscribe to Newsletter