Help Center/ Speech Interaction Service/ FAQs/ API/ How Do I Obtain a Token?
Updated on 2024-04-03 GMT+08:00

How Do I Obtain a Token?

Construct a token request as follows:

You can log in to the console and choose My Credentials to obtain the values of username, domainname, and project name. password indicates the user password.

Figure 1 My Credentials

If your Huawei Cloud account has been upgraded to a Huawei Cloud account, you cannot obtain a token. You are advised to create an IAM user and obtain the user token.

POST https://iam.ap-southeast-3.myhuaweicloud.com/v3/auth/tokens
Content-Type: application/json 
 
{ 
    "auth": { 
        "identity": { 
            "methods": [ 
                "password" 
            ], 
            "password": { 
                "user": { 
                    "name": "username", 
                    "password": "********", 
                    "domain": { 
                        "name": "domainname" 
                    } 
                } 
            } 
        }, 
        "scope": { 
            "project": { 
                "name": "region" 
            } 
        } 
    } 
}

As shown in the following figure, x-subject-token in the response header is the desired user token. This token can then be used to authenticate the calling of SIS APIs.

After obtaining the token, add the X-Auth-Token header field to requests to specify the token for calling other APIs. For example, if the token is ABCDEFJ...., add X-Auth-Token: ABCDEFJ.... to a request as follows:

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