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 Developer Toolkit > RESTful API.
- Click Add a secret, then click OK. Agora generates a customer ID and customer secret.
- Click Download in the Customer Secret column. Read the prompt carefully and save the downloaded
key_and_secret.txtfile in a secure location. - Use the customer ID and customer secret to generate a Base64-encoded credential, then pass it to the
Authorizationrequest header.
You can download the customer secret from Agora Console only once. Keep it secure.
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"))