English
English
简体中文
Contact Us
Register
Log In
layoutIndex

Authorization Management

Last Updated on : 2021-12-27 06:06:55download

This topic describes the related APIs of authorization management.

API list

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 Login-free token.

Get a token

API description

Get the token by the authorized credential generated from a cloud application created on the Tuya IoT Platform.

API address

GET /v1.0/token

Request parameter

Parameter Type Parameter type Required Description
grant_type Integer URL Yes Authorization type. 1: Simple mode.

Response parameter

Parameter Type Description
code Integer Response code. See Error code.
success Boolean Determine whether the request succeeded or not.
  • true: succeeded
  • false: failed
    msg String The message returned if the request fails. If the request succeeds, null is returned.
    result Object<result> Token information.

    Description of result

    Parameter Type Description
    uid String Tuya user ID.
    access_token String Access token.
    refresh_token String Refresh token.
    expire Integer Valid period in seconds.

    Sample request

    GET /v1.0/token?grant_type=1
    

    Sample response

    { "success":true, "result": { "uid":"euxxxxxxxxx", "access_token": "", "expire_time": 7200, "refresh_token": "" } }

    Error code

    The following are common service exceptions for this API. For more exception errors, see Error Code.

    Error code Description
    500 System error.
    1003 Invalid grant type.
    1107 Invalid code.

    Refresh token

    API description

    The OAuth token is currently valid for two hours for security concerns. After it has expired, you need to call refresh_token to get a new token.

    Note: The access_token has a validity period limit but no limit on the number of times. The refresh_token has no limit of the validity period but only takes effect once.

    API address

    GET /v1.0/token/{refresh_token}
    

    Sample request

    GET /v1.0/token/xxxxxx
    

    Sample response

    { "success":true, "result": { "uid":"euxxxxxxxxx", "access_token": "", "expire_time": 7200, "refresh_token": "" } }

    Error code

    The following are common service exceptions for this API. For more exception errors, see Error Code.

    Error code Description
    500 System error.
    1003 Invalid grant type.
    1107 Invalid code.

    Login-free token

    API description

    Generate a login-free token according to the Tuya user ID (UID). The token is used in certain scenarios or by some APIs.

    API address

    POST /v1.0/users/{uid}/ticket
    

    Request parameter

    Parameter Type Parameter type Required Description
    uid String URI Yes Tuya user ID.

    Sample request

    POST /v1.0/users/ay1541161424063AjySj/ticket
    

    Return parameter

    Parameter Type Description
    code Integer Response code. See Error code.
    success Boolean Determine whether the request succeeded or not.
    • true: succeeded
    • false: failed
      msg String The message returned if the request fails. If the request succeeds, null is returned.
      result Object Token information.

      Sample response

      { "success":true, "result":{ "ticket":"e0dcadc407806d0360a4df9f5b9f7942", "expire_time":300 } }

      Error code

      Error code Description
      500 System error.