Updated on 2024-02-21 GMT+08:00

Authentication

You can use either of the following authentication methods to call APIs:

  • Authentication using tokens: General requests are authenticated using tokens.
  • Authentication using AK/SK: Requests are encrypted using access key ID (AK)/secret access key (SK). This authentication method is recommended because it is more secure than token-based authentication.

Authentication Using Tokens

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

Ensure that the token is valid when you use it. Using a token that will soon expire may cause API calling failures.

A token specifies temporary permissions in a computer system. During API authentication using a token, the token is added to a request to get permissions for calling the API.

When calling an API to obtain a user token, you must set auth.scope in the request body to project.

{ 
	"auth": { 
		"identity": { 
			"methods": [ 
				"password" 
			], 
			"password": { 
				"user": { 
					"name": "username",   //Username
					"password": "********", //Password of the username
					"domain": { 
						"name": "domainname"    //Domain name which the user belongs to
					} 
				} 
			} 
		}, 
		"scope": { 
			"project": { 
				"id": "xxxxxxxx"    //Resource set ID
			} 
		} 
	} 
}

After a token is obtained, add field X-Auth-Token to the request header to specify the token when other APIs are called. For example, if the token is ABCDEFJ...., add X-Auth-Token: ABCDEFJ.... in a request as follows:

Content-Type: application/json
X-Auth-Token: ABCDEFJ....

Authentication Using AK/SK

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

This authentication method uses AK/SK to sign requests, and the signature is then added to request headers for authentication.

  • AK: access key ID. It is a unique identifier used with a secret access key to sign requests cryptographically.
  • SK: secret access key. It is used together with an AK to sign requests. They can identify request senders and prevent requests from being modified.
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.

The signing SDKs are only used for signing requests and different from the SDKs provided by services.