Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Wang , Deng Ke <wangdengke2@huawei.com> Co-committed-by: Wang , Deng Ke <wangdengke2@huawei.com>
7.9 KiB
Token Authentication
Application Scenarios
If you use a token for authentication, you must obtain the user's token and add X-Auth-Token to the request message header of the service API when making an API call.
This section describes how to make an API call for token authentication.
Invoking an API
- Obtain the following information:
- To obtain the IAM endpoint and region name in the message body, see Regions and Endpoints.
- To obtain the project ID, see Obtaining a Project ID.
- Send a POST https://IAM_Endpoint/v3/auth/tokens request to obtain the user token.
Table 1 Header description Name
Description
Mandatory
Example
Content-Type
Specifies the MIME type of the request body.
Yes
application/json
An example request message is as follows:{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", "password": "password", "domain": { "name": "domainname" } } } }, "scope": { "project": { "id": "project_id" } } } }
In the preceding command, replace parameter in italic with the actual values. For details, see the "Obtaining a User Token" section in the Identity and Access Management API Reference.
- IAM_Endpoint: Replace it with the IAM endpoint obtained in 1.
- username and password: Replace them respectively with the username and password of the IAM server.
- project_id: Replace it with the project ID obtained in 1.
After the request is processed, the value of X-Subject-Token in the header is the token value.
X-Subject-Token:MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...
- Run the following command to set the token as an environment variable for subsequent operations:
export Token={X-Subject-Token}
X-Subject-Token: Replace it with the token obtained in 2. An example command is as follows:
export Token=MIIDkgYJKoZIhvcNAQcCoIIDgzCCA38CAQExDTALBglghkgBZQMEAgEwgXXXXX...