Updated on 2022-06-20 GMT+08:00

Token-based Authentication

Application Scenario

For token-based authentication, you must obtain your token and add X-Auth-Token to the headers of API requests.

This section describes how to authorize API requests using tokens. For details about how to obtain a token, see Obtaining a User Token Through Password Authentication.

Procedure

  1. Send POST https://Endpoint of IAM/v3/auth/tokens to obtain the endpoint of Identity and Access Management (IAM) and the region name in the message body. For details, see Endpoint of IAM.
    Table 1 Endpoint of IAM

    Service Name

    Region Name

    Region

    Endpoint

    Protocol

    IAM

    CN-Hong Kong

    ap-southeast-1

    iam.ap-southeast-1.myhuaweicloud.com

    HTTPS

    Example request:
    {
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "username",//Replace the username as required.
              "password": "password",//Replace the password as required.
              "domain": {
                "name": "domainname"//Replace the domainname as required.
              }
            }
          }
        },
        "scope": {
          "project": {
            "name": "ap-southeast-1" //ap-southeast-1 indicates the IAM region. Replace it as required.
    
          }
        }
      }
    }
  2. Obtain a token. After a response is returned, the value of X-Subject-Token in the response header is the token value.
  3. Call a service API and add X-Auth-Token to the request header. The value of X-Auth-Token is the token value obtained in 2.