Updated on 2023-07-25 GMT+08:00

Signing a Request

API requests sent by third-party applications to Huawei Cloud must be authenticated using signatures.

Preparation

  1. Download the API Gateway signing tool and decompress it.
  2. Create a Java project and reference the decompressed JAR file to the dependency path.

Procedure

  1. Create a com.cloud.sdk.DefaultRequest (JAVA) request used for signing.
  2. Set the destination API URL, HTTPS method, and content of DefaultRequest.
  3. Sign DefaultRequest.
    1. Call SignerFactory.getSigner(String serviceName, String regionName) to obtain a signature tool instance.

      Call Signer.sign(Request<?> request, Credentials credentials) to sign the request created in step 1.

      The following code shows the details.

      // Select the signing algorithm for signing the request.
       Signer signer = SignerFactory.getSigner(serviceName, region);   
      // Sign the request. The request will change after being signed.
       signer.sign(request, new BasicCredentials(this.ak, this.sk));
  4. Convert the request signed in the previous step to one that can be used to make an API call and copy the header of the signed request to the new request.
  5. For example, for Apache HttpClient, convert DefaultRequest into HttpRequestBase and copy the header of the signed DefaultRequest to HttpRequestBase.