Obtaining a Temporary Access Key and SecurityToken Through an Agency
Function
This API is used to obtain a temporary access key and securityToken by using an agency.
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
| 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. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Yes | Object | Authentication information. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| methods | Yes | Array of strings | Authentication method. Set this parameter to ["assume_role"]. |
| Yes | Object | Details about the delegating account and agency. | |
| 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 agency and defined in this parameter. For details about the syntax and format of IAM policies, see Policies. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| agency_name | Yes | String | Agency name. For details about how to obtain the agency name, see Obtaining Account, IAM User, Group, Project, Region, and Agency Information. |
| domain_id | No | String | Account ID of the delegating party. Either domain_id or domain_name must be set. You are advised to specify domain_id. |
| domain_name | No | String | Account name of the delegating party. Either domain_id or domain_name must be set. You are advised to specify domain_id. |
| duration_seconds | No | Integer | Validity period (in seconds) of the AK/SK and securityToken. The value ranges from 15 minutes to 24 hours. The default value is 15 minutes. |
| No | Object | Enterprise user information of the delegating party. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | No | String | Enterprise user name of the delegating party. The username must be 5 to 32 characters long and start with a letter. Only letters, digits, hyphens (-), and underscores (_) are allowed. |
| 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. |
| Yes | Array of objects | Statement of the policy. A policy can contain a maximum of eight statements. |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Action | Yes | Array of strings | Specific operation permission on a resource. A maximum of 100 actions are allowed. NOTE:
|
| 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:
|
| 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:
|
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| Object | Authentication result. |
| 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 session_user parameter
POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
{ "auth": { "identity": { "methods": [ "assume_role" ], "assume_role": { "domain_name": "IAMDomainA", "agency_name": "IAMAgency", "duration_seconds": 3600, "session_user": { "name": "SessionUserName" } } } } } - Request with the policy parameter
POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
{ "auth": { "identity": { "methods": [ "assume_role" ], "policy": { "Version": "1.1", "Statement": [{ "Effect": "allow", "Action": [ "obs:object:*" ], "Resource": ["obs:*:*:object:*"], "Condition": { "StringEquals": { "obs:prefix": ["public"] } } }] }, "assume_role": { "domain_name": "IAMDomainA", "agency_name": "IAMAgency", "duration_seconds": 3600 } } } }
- Request without the session_user or policy parameter
POST https://iam.myhuaweicloud.com/v3.0/OS-CREDENTIAL/securitytokens
{ "auth": { "identity": { "methods": [ "assume_role" ], "assume_role": { "domain_name": "IAMDomainA", "agency_name": "IAMAgency", "duration_seconds": 3600 } } } }
Example Response
Status code: 201
The request is successful.
The responses to all the preceding requests are the same regardless of whether session_user is specified or not. If session_user is specified, the securityToken contains the corresponding enterprise user information.
{
"credential": {
"access": "E6DX0TF2ZREQ4Z...",
"expires_at": "2020-01-08T02:56:19.587000Z",
"secret": "w9ePum0qdfac39ErLD0UdjofYkqort6Iw....",
"securitytoken": "gQpjbi1ub3J0aC0..."
}
} 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
Last Article: Access Key Management
Next Article: Obtaining a Temporary Access Key and SecurityToken Through a Token
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.