Introduction

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.

Implementation

  1. 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.
  2. Get the Authorization parameter: type the Customer ID and Customer Certificate in the following sample code to obtain the Authorization parameter.

    • Java

      // 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()));
    • Swift

      // 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()
  3. Pass the basic HTTP authentication: fill in the Authorization parameter in the following sample code to pass the authentication.

    When sending the HTTP request, ensure that the format of Authorization is Basic <authorization>.

    • Java

      Request request = new Request.Builder()
      ...
          // Pass in the Authorization parameter in the HTTP request header.
          .addHeader("Authorization", "Basic " + base64Credentials)
      ...
    • Swift

      // Pass in the Authorization parameter in the HTTP request header.
      let headers = ["Authorization", "Basic " + base64LoginString]