Updated on 2023-12-18 GMT+08:00

Authentication

Requests for calling an API can be authenticated using either of the following methods:
  • Token-based authentication: Requests are authenticated using a token.
  • AK/SK-based authentication: Requests are authenticated by encrypting the request body using an AK/SK pair. AK/SK-based authentication is recommended because it is more secure than token-based authentication.

Token

The validity period of a token is 24 hours. When using a token for authentication, cache it to prevent frequently calling the IAM API used to obtain a user token.

A token specifies temporary permissions in a computer system. In token-based authentication, the token is added to requests to obtain permissions for calling an API.

In Making an API Request, the process of calling the API used to obtain a user token is described. After a token is obtained, the X-Auth-Token header field must be added to requests to specify the token for calling other APIs. For example, if the token is ABCDEFJ...., X-Auth-Token: ABCDEFJ.... can be added to a request as follows:

1
2
3
POST https://iam.cn-north-1.myhuaweicloud.com/v3/auth/projects
Content-Type: application/json
X-Auth-Token: ABCDEFJ....

AK/SK-Based Authentication

AK/SK-based authentication supports API requests with a body not larger than 12 MB. For API requests with a larger body, token-based authentication is recommended.

In AK/SK-based authentication, AK/SK is used to sign requests and the signature is then added to the requests for authentication.

  • AK indicates the ID of the access key, It is the unique ID associated with the SK. The AK and SK are used together to obtain an encrypted signature for a request.
  • SK indicates the secret access key used together with the AK to sign requests cryptographically. AK and SK can be used together to identify a request sender to prevent the request from being modified.

In AK/SK-based authentication, you can use an AK/SK to sign requests based on the signature algorithm or use the signing SDK to sign requests. For details about how to sign requests and use the signing SDK, see API Request Signing Guide.