更新时间:2024-03-01 GMT+08:00

如何获取Token?

调用接口时,可以使用Token进行认证鉴权,可以通过IAM标准接口获取Token,示例如下。

  • 获取华南区的Token示例命令如下。
    curl -k -i  -X POST   https://iam.cn-south-1.myhuaweicloud.com/v3/auth/tokens  -H 'Content-Type: application/json'  -d '{
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "华为云账号",
              "password": "华为云登录密码",
              "domain": {
                "name": "华为云账号"
              }
            }
          }
        },
        "scope": {
          "project": {
            "name": "cn-south-1"
          }
        }
      }
    }'
  • 获取华北区的Token示例命令如下。
    curl -k -i  -X POST   https://iam.cn-north-1.myhuaweicloud.com/v3/auth/tokens  -H 'Content-Type: application/json'  -d '{
      "auth": {
        "identity": {
          "methods": [
            "password"
          ],
          "password": {
            "user": {
              "name": "华为云账号",
              "password": "华为云登录密码",
              "domain": {
                "name": "华为云账号"
              }
            }
          }
        },
        "scope": {
          "project": {
            "name": "cn-north-1"
          }
        }
      }
    }'

    返回头中的X-Subject-Token对应的值即为获取的token值。例如获取华北-北京一区域的token,只能用于调用华北-北京一的FunctionGraph服务。

    具体请参考获取用户Token