Identity and Access ManagementIdentity and Access Management

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
LoT
LoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
HCloud CLI
Help Center> Identity and Access Management> API Reference> API> Access Key Management> Obtaining a Temporary Access Key and SecurityToken Through a Token
Updated at: Feb 22, 2022 GMT+08:00

Obtaining a Temporary Access Key and SecurityToken Through a Token

Function

This API is used to obtain a temporary access key and securityToken using a token. For details about how to obtain a token, see Obtaining a User Token Through Password Authentication.

A temporary access key and securityToken are issued by the system to IAM users, and can be valid for 15 minutes to 24 hours. The temporary access key and securityToken follow the principle of least privilege. A temporary access key must be used together with a securityToken, and the x-security-token field must be included in the request header. For more information, see How Do I Use a Temporary AK/SK to Sign Requests?

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

URI

POST /v3.0/OS-CREDENTIAL/securitytokens

Request Parameters

Table 1 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

IAM user token, federated user token, or agency token.

Table 2 Parameters in the request body

Parameter

Mandatory

Type

Description

auth

Yes

Object

Authentication information.

Table 3 auth

Parameter

Mandatory

Type

Description

identity

Yes

Object

Authentication parameters.

Table 4 auth.identity

Parameter

Mandatory

Type

Description

methods

Yes

Array of strings

Authentication method. The value of this field is ["token"].

token

No

Object

Validity period of a temporary access key and SecurityToken.

policy

No

Object

OBS permissions to be assigned to the temporary access key and securityToken.

The final permissions of the temporary access key and securityToken are all the permissions assigned to the specified user token and defined in this parameter.

For details about the syntax and format of IAM policies, see Policies.

Table 5 auth.identity.policy

Parameter

Mandatory

Type

Description

Version

Yes

String

Policy version. When creating a custom policy, set this parameter to 1.1.

NOTE:

1.1: Policy. A policy defines the permissions required to perform operations on a specific cloud resource under certain conditions.

Statement

Yes

Array of objects

Statement of the policy. A policy can contain a maximum of eight statements.

Table 6 auth.identity.policy.Statement

Parameter

Mandatory

Type

Description

Action

Yes

Array of strings

Specific operation permission on a resource. A maximum of 100 actions are allowed.

NOTE:
  • The value format is Service name:Resource type:Operation, for example, vpc:ports:create.
  • Service name: indicates the product name, such as ecs, evs, or vpc. Only lowercase letters are allowed. Resource types and operations are not case-sensitive. You can use an asterisk (*) to represent all operations.

Effect

Yes

String

Effect of the permission. The value can be Allow or Deny. If both Allow and Deny statements are found in a policy, the authentication starts from the Deny statements.

Options:

  • Allow
  • Deny

Condition

No

Map<String,Map<String,Array<String>>>

Conditions for the permission to take effect. A maximum of 10 conditions are allowed. For details about the condition parameters, see Creating a Custom Policy.

NOTE:

Take the condition in the sample request as an example, the values of the condition key (obs:prefix) and string (public) must be equal (StringEquals).

 "Condition": {
              "StringEquals": {
                "obs:prefix": [
                  "public"
                ]
              }
            }

Resource

No

Array of strings

Cloud resource. The array can contain a maximum of 10 resource strings, and each string cannot exceed 128 characters.

NOTE:
  • Format: Service name:Region:Account ID:Resource type:Resource path. Wildcard characters (*) are supported. For example, obs:*:*:bucket:* means all OBS buckets.
  • The region segment can be * or a region accessible to the user. The specified resource must belong to the corresponding service that actually exists.
Table 7 auth.identity.token

Parameter

Mandatory

Type

Description

duration_seconds

No

Integer

Validity period (in seconds) of a temporary access key and SecurityToken.

The value ranges from 15 minutes to 24 hours. The default value is 15 minutes.

Response Parameters

Table 8 Parameters in the response body

Parameter

Type

Description

credential

Object

Authentication result.

Table 9 credential

Parameter

Type

Description

expires_at

String

Expiration time of the access key and securityToken. The response is UTC time, which is 8 hours behind Beijing time.

For example:

"expires_at": "2020-01-08T02:56:19.587000Z"

Beijing time: 2020-01-08 10:56:19.587

access

String

AK.

secret

String

SK.

securitytoken

String

Obtained access key in ciphertext.

Example Request

  • Request with the token parameter
    POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
    {
        "auth": {
            "identity": {
                "methods": [
                    "token"
                ],
                "token": {
                    "duration_seconds": 900
                }
            }
        }
    }
  • Request with the X-Auth-Token header but without the token parameter
    POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
    {
        "auth": {
            "identity": {
                "methods": [
                    "token"
                ]
            }
        }
    }
  • Request with the policy parameter
    POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
    {
      "auth": {
        "identity": {
          "methods": [
            "token"
          ],
          "policy": {
            "Version": "1.1",
            "Statement": [
              {
                "Effect": "Allow",
                "Action": [
                  "obs:object:*"
                ],
                "Resource": [
                  "obs:*:*:object:*"
                ],
                "Condition": {
                  "StringEquals": {
                    "obs:prefix": [
                      "public"
                    ]
                  }
                }
              }
            ]
          },
          "token": {
            "duration_seconds": 900
          }
        }
      }
    }

Example Response

Status code: 201

The request is successful.

{
    "credential": {
        "access": "NZFAT5VNWEJDGZ4PZ...",
        "expires_at": "2020-01-08T03:50:07.574000Z",
        "secret": "riEoWsy3qO0BvgwfkoLVgCUvzgpjBBcvdq...",
        "securitytoken": "gQpjbi1ub3J0aC00jD4Ej..."
    }
}

Status Codes

Status Code

Description

201

The request is successful.

400

Invalid parameters.

401

Authentication failed.

403

Access denied.

500

Internal server error.

Error Codes

None

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel