Encrypted signature
The Provisioning, Usage, and Billing APIs have a request parameter named signature
. This parameter is an encrypted string shared between vendors and Agora. It allows vendors to verify HTTP requests sent by Agora.
This page explains how to generate a signature.
Overview
The signature combines the source string (SourceString
) and your secret key (apiSecret&
) using an encryption algorithm, as follows:
-
GET methods:
-
POST and PUT methods:
After receiving the request, you need to apply the encryption algorithm to generate a signature on your own. If the generated signature is the same as the one you receive, you can verify that the request is sent by Agora.
Generate a signature (GET)
Take the Usage API for example, Agora sends the following request to query usage information:
For this example, the parameters used in the encryption algorithm are as follows:
Parameter | Value |
---|---|
SourceString | GET&%2Fusage&apiKey%3DpzD5XinRSlmA64tZx81fL92YcBsJK0gd%26fromTs%3D1619913600%26pageNum%3D1%26toTs%3D1619917200 |
apiSecret | U1SXE6k57vxVRjTomgquwC2F3tH8ziOB (This is for demonstration only. Your actual apiSecret should be different.) |
signature | SFVnCVlRbrZcjMPGTWVxAE4QWZ8%3D |
This section shows how to generate the signature step-by-step.
Step 1: Construct the source string
To construct SourceString
, follow these steps:
-
Get the type of the HTTP request and add an "&":
-
In the request URL, leave only the path after
[host]
and before?
(if any), URL-encode the resulting string (that is,/usage
), and add an "&". The source string now looks like: -
Sequence the query parameters in the request URL except
signature
(that is,fromTs
,toTs
, andapiKey
) in alphabetical ascending order in the form ofkey=value
, and combine them using "&":URL-encode the string above and add it to the source string:
Step 2: Construct your secret key
To construct the secret key, add an “&” to the end of your apiSecret string.
For example, if the apiSecret you provide when applying to become a vendor is U1SXE6k57vxVRjTomgquwC2F3tH8ziOB, the secret key should be U1SXE6k57vxVRjTomgquwC2F3tH8ziOB&
.
Step 3: Generate the signature
The encryption algorithm for GET methods is as follows:
Using the SourceString
and apiSecret&
from previous steps, you get this signature:
Generate a signature (POST and PUT)
Take the Provisioning API for example, Agora sends the following request body:
And the request URL is:
For this example, the parameters used in the encryption algorithm are as follows:
Parameter | Value |
---|---|
SourceString | POST&%2Fcustomers%2F123456%2Fprojects%2Fnew&apiKey%3DpzD5XinRSlmA64tZx81fL92YcBsJK0gd%26projectId%3D430892 |
apiSecret | U1SXE6k57vxVRjTomgquwC2F3tH8ziOB (This is for demonstration only. Your actual apiSecret should be different.) |
signature | YZOl2v5q3I7o0x3F13tpnkq5aDI= |
This section shows how to generate the signature step-by-step.
Step 1: Construct the source string
To construct SourceString
, follow these steps:
-
Get the type of the HTTP request and add an "&":
-
In the request URL, leave only the path after
[host]
and before?
(if any), URL-encode the resulting string (that is,/usage
), and add an "&". The source string now looks like: -
Sequence the query parameters in the request body except
signature
(that is,projectId
andapiKey
) in alphabetical ascending order in the form ofkey=value
, and combine them using "&":URL-encode the string above and add it to the source string:
Step 2: Construct your secret key
To construct the secret key, add an “&” to the end of your apiSecret string.
For example, if the apiSecret you provide when applying to become a vendor is U1SXE6k57vxVRjTomgquwC2F3tH8ziOB, the secret key should be U1SXE6k57vxVRjTomgquwC2F3tH8ziOB&
.
Step 3: Generate the signature
The encryption algorithm for POST and PUT methods is as follows:
Using the SourceString
and apiSecret&
from previous steps, you get this signature: