Before using the Agora RESTful API, you need to type the
Authorization parameter in the HTTP request header for authentication. This page shows you how to generate the
Authorization parameter with the Customer ID and Customer Certificate provided by Agora.
Get the Customer ID and Customer Certificate: log in to Agora Console, click the account name on the top right of Agora Console, and enter the RESTful API page from the drop-down list to get the Customer ID and Customer Certificate.The Customer ID and Customer Certificate are used for RESTful API access only.
Authorizationparameter: type the Customer ID and Customer Certificate in the following sample code to obtain the
// Fill in the Customer ID and Customer Certificate to obtain the plainCredentials value. String plainCredentials = "customerId:customerCertificate"; // Fill in the plainCredentials (the base64 encoding of the credential) to obtain the base64Credentials value which is the Authorization parameter you want. String base64Credentials = new String(Base64.encodeBase64(plainCredentials.getBytes()));
// Fill in the Customer ID and Customer Certificate to obtain the loginString value. let username = "customerId" let password = "customerCertificate" let loginString = String(format: "%@:%@", username, password) // Fill in the loginString to obtain the loginData value. let loginData = loginString.data(using: String.Encoding.utf8)! // Fill in the loginData (the base64 encoding of the loginData) to obtain the base64LoginString value which is the Authorization parameter you want. let base64LoginString = loginData.base64EncodedString()
Pass the basic HTTP authentication: fill in the
Authorizationparameter in the following sample code to pass the authentication.
When sending the HTTP request, ensure that the format of Authorization is
Request request = new Request.Builder() ... // Pass in the Authorization parameter in the HTTP request header. .addHeader("Authorization", "Basic " + base64Credentials) ...
// Pass in the Authorization parameter in the HTTP request header. let headers = ["Authorization", "Basic " + base64LoginString]