Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Obtaining an Agency Token

Updated on 2024-11-18 GMT+08:00

Function

This API is used to obtain an agency token.

For example, after a trust relationship is established between A and B, A is the delegating party and B is the delegated party. Then B can use this API to obtain an agency token. The obtained agency token can only be used to manage the resources that account B is delegated to manage. If account B needs to manage their own resources, account B needs to obtain a user token. For details, see Delegating Resource Access to Another Account.

A token is an access credential issued to a user to bear its identity and permissions. When calling the APIs of IAM or other cloud services, you can use this API to obtain a token for authentication.

The API can be called using both the global endpoint and region-specific endpoints. For IAM endpoints, see Regions and Endpoints.

NOTE:
  • The validity period of a token is 24 hours. Cache the token to prevent frequent API calling.
  • Ensure that the token is valid while you use it. Using a token that will soon expire may cause API calling failures.

Debugging

You can debug this API in API Explorer.

URI

POST /v3/auth/tokens

Table 1 Query parameters

Parameter

Mandatory

Type

Description

nocatalog

No

String

If this parameter is set, no catalog information will be displayed in the response. Any character string set for this parameter indicates that no catalog information will be displayed.

Request Parameters

Table 2 Parameters in the request header

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Fill application/json;charset=utf8 in this field.

X-Auth-Token

Yes

String

Token with Agent Operator permissions of an IAM user created by delegated party B.

Table 3 Parameters in the request body

Parameter

Mandatory

Type

Description

auth

Yes

Object

Authentication information.

Table 4 auth

Parameter

Mandatory

Type

Description

identity

Yes

Object

Authentication parameters.

scope

Yes

Object

Usage scope of the token. The value can be project or domain.

NOTE:
  • If the scope is set to domain, the token applies to global services. If the scope is set to project, the token applies to project-level services.
  • If the scope is set to both project and domain, the project is used and you get a token for project-level services.
  • If the scope is left blank, you get a token for global services. You are advised to specify this parameter.
Table 5 auth.identity

Parameter

Mandatory

Type

Description

methods

Yes

Array of strings

Method for obtaining the token. Set this parameter to assume_role.

assume_role

Yes

Object

Details about the delegating account and agency.

Table 6 auth.identity.assume_role

Parameter

Mandatory

Type

Description

domain_id

No

String

Account ID of delegating party A. Either domain_id or domain_name must be set. You are advised to specify domain_id.

For details about how to obtain the account ID, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information.

domain_name

No

String

Account name of delegating party A. Either domain_id or domain_name must be set. You are advised to specify domain_id.

You can view the account name of delegating party A in the agency list on the IAM console.

agency_name

Yes

String

Name of the agency created by delegating party A. For details about how to obtain the agency name, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information.

Table 7 auth.scope

Parameter

Mandatory

Type

Description

domain

No

Object

If this parameter is set to domain, the token can be used to access global services, such as OBS. Global services are not subject to any projects or regions. For details about the service scope, see System Permissions. You can specify either id or name. domain_id is recommended.

project

No

Object

If this parameter is set to project, the token can be used to access only services in specific projects, such as ECS. For details about the service scope, see System Permissions. You can specify either id or name.

Table 8 auth.scope.domain

Parameter

Mandatory

Type

Description

id

No

String

Account ID of delegating party A. For details about how to obtain the account ID, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information. You can specify either id or name.

name

No

String

Account name of delegating party A. For details about how to obtain the account name, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information. You can specify either id or name.

Table 9 auth.scope.project

Parameter

Mandatory

Type

Description

id

No

String

Project ID of delegating party A. For details about how to obtain the project ID, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information. You can specify either id or name.

name

No

String

Project name of delegating party A. For details about how to obtain the project name, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information. You can specify either id or name.

Example Request

  • Request for using a user token with Agent Operator permissions of IAM user IAMUserB of delegated party B (account name: IAMDomainB) to obtain another token to manage the resources of delegating party A (account name: IAMDomainA) in the ap-southeast-1 project through agency IAMAgency, without displaying catalog information in the response
    POST https://iam.myhuaweicloud.com/v3/auth/tokens?nocatalog=true
    {
        "auth": {
            "identity": {
                "methods": [
                    "assume_role"
                ],
                "assume_role": {
                    "domain_name": "IAMDomainA",                // Name of the account which the delegating party IAM user A belongs to
                    "agency_name": "IAMAgency"                  // Name of the agency created by IAM user A
                }
            },
            "scope": {
                "project": {
                    "name": "ap-southeast-1"                         //Project name
                }
            }
        }
    }
  • Request for using a user token with Agent Operator permissions of IAM user IAMUserB of delegated party B (account name: IAMDomainB) to obtain another token to manage all resources of delegating party A (account name: IAMDomainA) through agency IAMAgency
    POST https://iam.myhuaweicloud.com/v3/auth/tokens
    {
        "auth": {
            "identity": {
                "methods": [
                    "assume_role"
                ],
                "assume_role": {
                    "domain_name": "IAMDomainA",                // Name of the account which the delegating party IAM user A belongs to
                    "agency_name": "IAMAgency"                  // Name of the agency created by IAM user A
                }
            },
            "scope": {
                "domain": {
                    "name": "IAMDomainA"                        // Name of the account which the delegating party IAM user A belongs to
                }
            }
        }
    }

Response Parameters

Table 10 Parameters in the response header

Parameter

Type

Description

X-Subject-Token

String

Signed token.

Table 11 Parameters in the response body

Parameter

Type

Description

token

Object

Token information.

Table 12 token

Parameter

Type

Description

methods

Array of strings

Method for obtaining the token.

expires_at

String

Time when the token will expire.

NOTE:

The value is a UTC time in the YYYY-MM-DDTHH:mm:ss.ssssssZ format, for example, 2023-06-28T08:56:33.710000Z. For details about the date and timestamp formats, see ISO-8601.

issued_at

String

Time when the token was issued.

NOTE:

The value is a UTC time in the YYYY-MM-DDTHH:mm:ss.ssssssZ format, for example, 2023-06-28T08:56:33.710000Z. For details about the date and timestamp formats, see ISO-8601.

assumed_by

Object

Information about delegated party B.

catalog

Array of objects

Catalog information.

domain

Object

Account information about delegating party A. This parameter is returned only when the scope parameter in the request body has been set to domain.

project

Object

Project information about delegating party A. This parameter is returned only when the scope parameter in the request body has been set to project.

roles

Array of objects

Permissions information of the token.

user

Object

Information about the agency created by delegating party A.

Table 13 token.assumed_by

Parameter

Type

Description

user

Object

Information about an IAM user of delegated party B.

Table 14 token.assumed_by.user

Parameter

Type

Description

name

String

IAM username.

id

String

IAM user ID.

domain

Object

Account information about delegated party B.

password_expires_at

String

Password expiration time of the IAM user. If this parameter is not specified, the password will never expire.

NOTE:

The value is a UTC time in the YYYY-MM-DDTHH:mm:ss.ssssssZ format, for example, 2023-06-28T08:56:33.710000Z. For details about the date and timestamp formats, see ISO-8601.

Table 15 token.assumed_by.user.domain

Parameter

Type

Description

name

String

Account name of delegated party B.

id

String

Account ID of delegated party B.

Table 16 token.catalog

Parameter

Type

Description

endpoints

Array of objects

Endpoint information.

id

String

Service ID.

name

String

Service name.

type

String

Type of the service which the API belongs to.

Table 17 token.catalog.endpoints

Parameter

Type

Description

id

String

Endpoint ID.

interface

String

Visibility of the API. public indicates that the API is available for public access.

region

String

Region which the endpoint belongs to.

region_id

String

Region ID.

url

String

Endpoint URL.

Table 18 token.domain

Parameter

Type

Description

name

String

Account name of delegating party A.

id

String

Account ID of delegating party A.

Table 19 token.project

Parameter

Type

Description

name

String

Project name of delegating party A.

id

String

Project ID of delegating party A.

domain

Object

Account information about delegating party A.

Table 20 token.project.domain

Parameter

Type

Description

name

String

Account name of delegating party A.

id

String

Account ID of delegating party A.

Table 21 token.roles

Parameter

Type

Description

name

String

Permission name.

id

String

Permission ID. The default value is 0, which does not correspond to any permission.

Table 22 token.user

Parameter

Type

Description

name

String

Account name or agency name of delegating party A.

id

String

Agency ID.

domain

Object

Account information about delegating party A.

Table 23 token.user.domain

Parameter

Type

Description

id

String

Account ID of delegating party A.

name

String

Account name of delegating party A.

Example Response

Status code: 201

The request is successful.

Example 1: Response to the request for using a user token with Agent Operator permissions of IAM user IAMUserB of delegated party B (account name: IAMDomainB) to obtain another token to manage all resources of delegating party A (account name: IAMDomainA) through agency IAMAgency

Example 2: Response to the request for using a user token with Agent Operator permissions of IAM user IAMUserB of delegated party B (account name: IAMDomainB) to obtain another token to manage the resources of delegating party A (account name: IAMDomainA) in the ap-southeast-1 project through agency IAMAgency, without displaying catalog information in the response

  • Example 1
    Parameters in the response header
    X-Subject-Token:MIIatAYJKoZIhvcNAQcCoIIapTCCGqECAQExDTALB...
    Parameters in the response body
    {
        "token": {
            "expires_at": "2020-01-05T05:05:17.429000Z",
            "methods": [
                "assume_role"
            ],
            "catalog": [
                {
                    "endpoints": [
                        {
                            "id": "33e1cbdd86d34e89a63cf8ad16a5f49f",
                            "interface": "public",
                            "region": "*",
                            "region_id": "*",
                            "url": "https://iam.myhuaweicloud.com/v3.0"
                        }
                    ],
                    "id": "100a6a3477f1495286579b819d399e36",
                    "name": "iam",
                    "type": "iam"
                }
            ],
            "domain": {
                "id": "d78cbac186b744899480f25bd022f468",
                "name": "IAMDomainA"
            },
            "roles": [
                {
                    "id": "0",
                    "name": "op_gated_eip_ipv6"
                },
                {
                    "id": "0",
                    "name": "op_gated_rds_mcs"
                }
            ],
            "issued_at": "2020-01-04T05:05:17.429000Z",
            "user": {
                "domain": {
                    "id": "d78cbac186b744899480f25bd022f468",
                    "name": "IAMDomainA"
                },
                "id": "0760a9e2a60026664f1fc0031f9f205e",
                "name": "IAMDomainA/IAMAgency"
            },
            "assumed_by": {
                "user": {
                    "domain": {
                        "id": "a2cd82a33fb043dc9304bf72a0f38f00",
                        "name": "IAMDomainB"
                    },
                    "id": "0760a0bdee8026601f44c006524b17a9",
                    "name": "IAMUserB",
                    "password_expires_at": ""
                }
            }
        }
    }
  • Example 2
    Parameters in the response header
    X-Subject-Token:MIIatAYJKoZIhvcNAQcCoIIapTCCGqECAQExDTALB...
    Parameters in the response body
    {
        "token": {
            "expires_at": "2020-01-05T06:49:28.094000Z",
            "methods": [
                "assume_role"
            ],
            "catalog": [],
            "roles": [
                {
                    "id": "0",
                    "name": "op_gated_eip_ipv6"
                },
                {
                    "id": "0",
                    "name": "op_gated_rds_mcs"
                }
            ],
            "project": {
                "domain": {
                    "id": "d78cbac186b744899480f25bd022f468",
                    "name": "IAMDomainA"
                },
                "id": "aa2d97d7e62c4b7da3ffdfc11551f878",
                "name": "ap-southeast-1"
            },
            "issued_at": "2020-01-04T06:49:28.094000Z",
            "user": {
                "domain": {
                    "id": "d78cbac186b744899480f25bd022f468",
                    "name": "IAMDomainA"
                },
                "id": "0760a9e2a60026664f1fc0031f9f205e",
                "name": "IAMDomainA/IAMAgency"
            },
            "assumed_by": {
                "user": {
                    "domain": {
                        "id": "a2cd82a33fb043dc9304bf72a0f38f00",
                        "name": "IAMDomainB"
                    },
                    "id": "0760a0bdee8026601f44c006524b17a9",
                    "name": "IAMUserB",
                    "password_expires_at": ""
                }
            }
        }
    }

Status code: 400

Invalid parameters.

{
    "error": {
        "code": 400,
        "message": "The request body is invalid",
        "title": "Bad Request"
    }
}

Status code: 401

Authentication failed.

{
    "error": {
        "code": 401,
        "message": "The X-Auth-Token is invalid!",
        "title": "Unauthorized"
    }
}

Status code: 403

Access denied.

  • The user token specified in X-Auth-Token for user B of delegated party B does not have the Agent Operator permission. Please apply for the required permission.
{
    "error": {
        "code": 403,
        "message": "You have no right to do this action",
        "title": "Forbidden"
    }
}

Status Codes

Status Code

Description

201

The request is successful.

400

Invalid parameters.

401

Authentication failed.

403

Access denied. The possible cause of this error is that the delegated party does not have the Agent Operator permission.)

404

The requested resource cannot be found.

500

Internal server error.

503

Service unavailable.

Error Codes

None

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback