Last Updated on : 2024-10-23 06:44:31download
This topic describes the APIs related to authorization management.
Request method | API | Description |
---|---|---|
GET | /v1.0/token | Get the access token. |
GET | /v1.0/token/{refresh_token} | Refresh the user token. |
POST | /v1.0/users/{uid}/ticket | Generate a login-free token. |
Get a token by using the authorized credential generated from a cloud application created on Tuya Developer Platform. You can get a token in simple mode or authorization mode. For differences between the two modes, see Authorization Mode.
GET /v1.0/token
Parameter | Type | Parameter type | Required | Description |
---|---|---|---|---|
grant_type | Integer | URL | Yes | The authorization type.
|
code | String | URL | No | The authorization code, which is required if grant_type is set to 3. For more information, see Authorization Mode. |
associate_id | String | URL | No | The association ID, which is required if grant_type is set to 3. For more information, see Authorization Mode. |
Parameter | Type | Description |
---|---|---|
code | Integer | The response code. For more information, see Error code. |
success | Boolean | Indicates whether the request succeeds.
|
msg | String | The message returned if the request fails. If the request succeeds, null is returned. |
result | Object<result> | The token information. |
Result details
Parameter | Type | Description |
---|---|---|
uid | String | The ID of the Tuya user. |
access_token | String | The access token. |
refresh_token | String | The refresh token. |
expire | Integer | The valid period, in seconds. |
GET /v1.0/token?grant_type=1
{
"success":true,
"result": {
"uid":" euxxxxxxxxx",
"access_token": "",
"expire_time": 7200,
"refresh_token": ""
}
}
The following error codes indicate common service exceptions returned by this API. For more error codes, see Global Error Codes.
Error code | Description |
---|---|
500 | The system error. |
1003 | The invalid grant type. |
1107 | The invalid code. |
The OAuth token
is currently valid only for two hours for security concerns. After it expires, you must call refresh_token
to get a new token.
access_token
has a limited validity period but no restrictions on the number of times it can be used during that period.refresh_token
does not have a validity period limit but can only be used once.GET /v1.0/token/{refresh_token}
GET /v1.0/token/xxxxxx
{
"success":true,
"result": {
"uid":" euxxxxxxxxx",
"access_token": "",
"expire_time": 7200,
"refresh_token": ""
}
}
The following error codes indicate common service exceptions returned by this API. For more error codes, see Global Error Codes.
Error code | Description |
---|---|
500 | The system error. |
1003 | The invalid grant type. |
1107 | The invalid code. |
Generate a login-free token based on the Tuya user ID (UID). The token is used in specific scenarios or required by certain APIs.
POST /v1.0/users/{uid}/ticket
Parameter | Type | Parameter type | Required | Description |
---|---|---|---|---|
uid | String | URI | Yes | The ID of the Tuya user. |
POST /v1.0/users/ay1541161424063AjySj/ticket
Parameter | Type | Description |
---|---|---|
code | Integer | The response code. For more information, see Error code. |
success | Boolean | Indicates whether the request succeeds.
|
msg | String | The message returned if the request fails. If the request succeeds, null is returned. |
result | Object | The token information. |
{
"success":true,
"result": {
"ticket":" e0dcadc407806d0360a4df9f5b9f7942",
"expire_time":300
}
}
Error code | Description |
---|---|
500 | The system error. |
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback