Modern OAuth2 Bearer Token Authentication via api.mobile.digital
OAuth2 is an industry-standard protocol for authorization. The Client Credentials flow is designed for machine-to-machine authentication where your application authenticates using a client ID and client secret to obtain an access token.
You'll receive from your account administrator:
client_id - Your unique client identifierclient_secret - Your secret key (keep this confidential!)Send a POST request to the token endpoint with your credentials to receive an access token.
Include the access token in the Authorization header of all API requests as a Bearer token.
POST https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/oauth2/token
Headers:
Authorization: Basic <base64(client_id:client_secret)>Content-Type: application/x-www-form-urlencodedBody (x-www-form-urlencoded):
grant_type=client_credentials (required)scope=read write admin (optional, space-separated scopes){
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "read write admin"
}
Include the access token in the Authorization header:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
POST https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/sendSMS
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json
{
"recipient": "+61400000000",
"message": "Hello from OAuth2!"
}
Access tokens expire after 1 hour (3600 seconds). When a token expires:
import requests
import base64
import json
# Your credentials
client_id = "your_client_id"
client_secret = "your_client_secret"
# Encode credentials for Basic Auth
credentials = f"{client_id}:{client_secret}"
encoded_credentials = base64.b64encode(credentials.encode()).decode()
# Get access token
token_url = "https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/oauth2/token"
token_headers = {
"Authorization": f"Basic {encoded_credentials}",
"Content-Type": "application/x-www-form-urlencoded"
}
token_data = {
"grant_type": "client_credentials",
"scope": "read write admin"
}
response = requests.post(token_url, headers=token_headers, data=token_data)
token_response = response.json()
access_token = token_response["access_token"]
print(f"Access Token: {access_token}")
# Use token to make API call
api_url = "https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/sendSMS"
api_headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
api_data = {
"recipient": "+61400000000",
"message": "Hello from Python!"
}
api_response = requests.post(api_url, headers=api_headers, json=api_data)
print(f"API Response: {api_response.json()}")
# Step 1: Get access token
curl -X POST 'https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/oauth2/token' \
-H 'Authorization: Basic $(echo -n "client_id:client_secret" | base64)' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials&scope=read write admin'
# Step 2: Use token in API call
curl -X POST 'https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/sendSMS' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"recipient": "+61400000000", "message": "Hello!"}'
<?php
$client_id = "your_client_id";
$client_secret = "your_client_secret";
// Get access token
$credentials = base64_encode("$client_id:$client_secret");
$token_url = "https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/oauth2/token";
$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Basic $credentials",
"Content-Type: application/x-www-form-urlencoded"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials&scope=read write admin");
$response = curl_exec($ch);
$token_data = json_decode($response, true);
$access_token = $token_data['access_token'];
curl_close($ch);
// Use token for API call
$api_url = "https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/sendSMS";
$api_data = json_encode([
"recipient" => "+61400000000",
"message" => "Hello from PHP!"
]);
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $access_token",
"Content-Type: application/json"
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $api_data);
$api_response = curl_exec($ch);
echo "API Response: $api_response\n";
curl_close($ch);
?>
const axios = require('axios');
const clientId = 'your_client_id';
const clientSecret = 'your_client_secret';
// Get access token
async function getAccessToken() {
const credentials = Buffer.from(`${clientId}:${clientSecret}`).toString('base64');
const response = await axios.post(
'https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/oauth2/token',
'grant_type=client_credentials&scope=read write admin',
{
headers: {
'Authorization': `Basic ${credentials}`,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
);
return response.data.access_token;
}
// Use token for API call
async function sendSMS() {
const accessToken = await getAccessToken();
const response = await axios.post(
'https://ah1ta9hc59.execute-api.ap-southeast-2.amazonaws.com/prod/sendSMS',
{
recipient: '+61400000000',
message: 'Hello from Node.js!'
},
{
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
}
);
console.log('API Response:', response.data);
}
sendSMS().catch(console.error);
| Scope | Description | Example Operations |
|---|---|---|
read |
Read-only access to resources | View campaigns, check balances, list triggers |
write |
Create and update resources | Send SMS/MMS, create campaigns, update triggers |
admin |
Full administrative access | Manage webhooks, delete resources, configure settings |
| Scope | Description |
|---|---|
gifting:send |
Send gifts and trigger delivery |
gifting:links |
Create MDV-gated short links |
gifting:webhooks |
Manage gifting webhook subscriptions |
gifting:fraud.read |
Read MDV policy and fraud decisions |
gifting:fraud.write |
Trigger OTP and fraud scoring |
gifting:trace |
Access gifting correlation history |
Request multiple scopes by separating them with spaces:
scope=read write admin gifting:send gifting:links
| HTTP Status | Error | Description | Solution |
|---|---|---|---|
401 |
Unauthorized | Invalid or expired token | Request a new access token |
401 |
Invalid credentials | Wrong client_id or client_secret | Check your credentials |
403 |
Forbidden | Missing required scope | Request token with appropriate scopes |
400 |
Bad Request | Invalid grant_type or parameters | Use grant_type=client_credentials |
{
"error": "invalid_client",
"error_description": "Client authentication failed"
}
/test-oauth2 endpoint to validateFor command-line testing, use our token generator scripts: