RESTful authentication
Updated
Authenticate RTC REST API requests with Basic HTTP authentication.
RTC REST APIs require Basic HTTP authentication. Generate a Base64-encoded credential with the customer ID and customer secret provided by Agora, then pass the credential in the Authorization request header.
Implement authentication on your server to reduce the risk of credential leakage.
Generate a customer ID and customer secret
-
In Agora Console, click the username at the bottom of the navigation sidebar to open the account menu, then select RESTful API Keys.
-
Select Create API Key. Agora generates a customer ID and customer secret.
-
Select Download and save the file somewhere secure — you can download it only once. In the file, Key is your customer ID and Secret is your customer secret.
-
Use the customer ID (Key) and customer secret (Secret) to generate a Base64-encoded credential, then pass it to the
Authorizationrequest header.
Authorization header
Concatenate the customer ID and customer secret with a colon, encode the result with Base64, then prefix it with Basic.
Authorization: Basic <base64(customer_id:customer_secret)>For testing and debugging, you can use a Basic Auth header generator. Enter the customer ID as the username and the customer secret as the password.
Basic authentication examples
The following examples send a request to get all projects under your Agora account.
customer_key="Your customer ID"
customer_secret="Your customer secret"
authorization=$(printf "%s:%s" "$customer_key" "$customer_secret" | base64)
curl --request GET 'https://api.agora.io/dev/v1/projects' \
--header "Authorization: Basic $authorization" \
--header 'Content-Type: application/json'const https = require('https');
const customerKey = 'Your customer ID';
const customerSecret = 'Your customer secret';
const encodedCredential = Buffer.from(
`${customerKey}:${customerSecret}`,
).toString('base64');
const req = https.request(
{
hostname: 'api.agora.io',
port: 443,
path: '/dev/v1/projects',
method: 'GET',
headers: {
Authorization: `Basic ${encodedCredential}`,
'Content-Type': 'application/json',
},
},
(res) => {
console.log(`Status code: ${res.statusCode}`);
res.on('data', (chunk) => process.stdout.write(chunk));
},
);
req.on('error', console.error);
req.end();import base64
import http.client
customer_key = "Your customer ID"
customer_secret = "Your customer secret"
credential = base64.b64encode(
f"{customer_key}:{customer_secret}".encode("utf-8")
).decode("utf-8")
conn = http.client.HTTPSConnection("api.agora.io")
headers = {
"Authorization": f"Basic {credential}",
"Content-Type": "application/json",
}
conn.request("GET", "/dev/v1/projects", "", headers)
res = conn.getresponse()
print(res.read().decode("utf-8"))