ApplyToken
Call the ApplyToken operation to create a temporary access token.
Scenarios
The application server must initiate the API call to request a token. After the application server verifies the permission scope of the ApsaraMQ for MQTT client, it requests a token from the ApsaraMQ for MQTT server on behalf of the client. For more information, see Token-based authentication.
Limits
The request frequency is limited to 500 calls per second for each user. If you have special requirements, you can submit a ticket.
Debug
Request parameters
| Name | Type | Required | Example | Description |
| Action | String | Yes | ApplyToken | A required parameter. Set the value to ApplyToken. |
| Actions | String | Yes | R | The permission type of the token. Valid values:
|
| ExpireTime | Long | Yes | 1578399620000 | The UNIX timestamp in milliseconds when the token expires. The minimum validity period is 60 seconds and the maximum is 30 days. If you specify a validity period longer than 30 days, the API call does not return an error, but the token is valid for only 30 days. |
| InstanceId | String | Yes | post-cn-0pp12gl**** | The ID of the ApsaraMQ for MQTT instance. This must match the ID of the instance that the client uses. Obtain this ID from the Instance Details page in the console. |
| RegionId | String | Yes | mq-internet-access | The region where the ApsaraMQ for MQTT instance resides. |
| Resources | String | Yes | TopicA/+ | The name of the resource, which is an MQTT topic. To specify multiple topics, separate them with commas (,). Each token can be used for operations on a maximum of 100 resources. If you specify multiple topics, sort them in alphabetical order. The resource parameter supports MQTT wildcard syntax, including the single-level wildcard character (+) and the multi-level wildcard character (#). For example, if you set resources to "Topic1/+", the client can operate on any topic that is a direct child of "Topic1". If you set resources to "Topic1/#", the client can operate on any topic in the "Topic1" hierarchy. |
Returned data
| Name | Type | Example | Description |
| RequestId | String | 31782AAF-D0CC-44C3-ABFD-1B500276F8CD | A common parameter. The unique ID of the request. |
| Token | String | LzMT+XLFl5s/YWJ/MlDz4t/Lq5HC1iGU1P28HAMaxYxn8aQbALNtml7QZKl9L9kPe6LqUb95tEVo+zUqOogs9+jZwDUSzsd4X4qaD3n2TrBEuMOqKkk1Xdrvu9VBQQvIYbz7MJWZDYC3DlW7gLEr33Cuj54iIhagtBi3epStJitsssWs7otY9zhKOSZxhr49G3d0bh35mwyP18EMvDas8UlzeSozsSrujNUqZXOGK0PEBSd+rWMGDJlCt6GFmJgm2JFY7PJwf/7OOSmUYIYFs5o/PuPpoTMF+hcVXMs+0yDukIMTOzG9m3t8k36PVrghFmnK6pC3Rt3mibjW****ng== | The token returned by the server. Note Do not make any assumptions about the length, format, or rules of the returned token. Use the exact value that is returned. |
Examples
Sample request
http(s)://onsmqtt.cn-hangzhou.aliyuncs.com/?Action=ApplyToken
&Actions=R
&ExpireTime=1578399620000
&InstanceId=post-cn-0pp12gl****
&RegionId=mq-internet-access
&Resources=TopicA/+
&<Common request parameters>Sample success response
XML format
<RequestId>31782AAF-D0CC-44C3-ABFD-1B500276F8CD</RequestId>
<Token>LzMT+XLFl5s/YWJ/MlDz4t/Lq5HC1iGU1P28HAMaxYxn8aQbALNtml7QZKl9L9kPe6LqUb95tEVo+zUqOogs9+jZwDUSzsd4X4qaD3n2TrBEuMOqKkk1Xdrvu9VBQQvIYbz7MJWZDYC3DlW7gLEr33Cuj54iIhagtBi3epStJitsssWs7otY9zhKOSZxhr49G3d0bh35mwyP18EMvDas8UlzeSozsSrujNUqZXOGK0PEBSd+rWMGDJlCt6GFmJgm2JFY7PJwf/7OOSmUYIYFs5o/PuPpoTMF+hcVXMs+0yDukIMTOzG9m3t8k36PVrghFmnK6pC3Rt3mibjW****ng==</Token>JSON format
{
"RequestId": "31782AAF-D0CC-44C3-ABFD-1B500276F8CD",
"Token": "LzMT+XLFl5s/YWJ/MlDz4t/Lq5HC1iGU1P28HAMaxYxn8aQbALNtml7QZKl9L9kPe6LqUb95tEVo+zUqOogs9+jZwDUSzsd4X4qaD3n2TrBEuMOqKkk1Xdrvu9VBQQvIYbz7MJWZDYC3DlW7gLEr33Cuj54iIhagtBi3epStJitsssWs7otY9zhKOSZxhr49G3d0bh35mwyP18EMvDas8UlzeSozsSrujNUqZXOGK0PEBSd+rWMGDJlCt6GFmJgm2JFY7PJwf/7OOSmUYIYFs5o/PuPpoTMF+hcVXMs+0yDukIMTOzG9m3t8k36PVrghFmnK6pC3Rt3mibjW****ng=="
}Error codes
| HTTP status code | Error code | Error message | Description |
| 404 | ApiNotSupport | The specified API is not supported. | The API is not supported. Check your request. |
| 400 | ApplyTokenOverFlow | You have applied for tokens too many times. Please try again later. | The frequency of token requests is too high. The system is throttling the requests. Try again later. |
| 400 | CheckAccountInfoFailed | An error occurred while checking the account information by the STS token. | Failed to parse the account information from the Security Token Service (STS) token. |
| 400 | InstancePermissionCheckFailed | An error occurred while validating the permissions of the instance. Please verify the account that created the instance and its permissions settings. | Instance permission check failed. Confirm the ownership and authorization policy of the ApsaraMQ for MQTT instance. |
| 500 | InternalError | An error occurred while processing your request. Try again later. | An error occurred in the ApsaraMQ for MQTT backend service. Try again later. |
| 400 | ParameterCheckFailed | An error occurred while validating the parameters. The parameters may be missing or invalid. | Parameter verification failed. A parameter may be missing or invalid. |
| 400 | PermissionCheckFailed | An error occurred while validating the resource permissions. Please check the account that created the instance, topic, and GroupId, and check their permission settings. | Resource permission check failed. Check the ownership and authorization policies for the instance, topic, and group ID. |
| 500 | SystemOverFlow | An error occurred while processing your request. Please try again. | The system is throttling the requests. Try again later. |
| 400 | InvalidParameter.%s | An error occurred while validating the parameter. The parameter may be missing or invalid. | Parameter verification failed. A parameter may be missing or invalid. |
For a list of additional error codes, visit the Error Center.