OAuth with the third-party device cloud

Next, connect to the third-party device cloud, and issue a GET request for a device list for the user.

When your SmartThings Connector receives the device list from the third-party device cloud, the SmartThings Connector should then issue requests to create a device in SmartThings Cloud for each device in that list. This step must occur in the PAGE phase of the CONFIGURATION lifecycle phase, while the SmartThings Connector is being installed.

See the picture below:

Create cloud device

Here is an example of a request body showing the PAGE settings for the authentication request into the LIFX cloud.


"settings": [
    {
        "id": "LIFX OAuth",
        "name": "LIFX OAuth",
        "description": "Authentication request into the LIFX cloud",
        "urlTemplate": "https://cloud.lifx.com/oauth/authorize?client_id=$clientId&scope=remote_control:all&response_type=code&redirect_uri=https%3A%2F%2Fapi.smartthings.com%2Foauth%2Fcallback",
        "required": true,
        "type": "OAUTH"
    }
]

The LIFX cloud will respond to SmartThings Cloud with a urlPath string that contains the necessary authorization and tokens. SmartThings Cloud will then call the SmartThings Connector with this urlPath with the lifecycle of OAUTH_CALLBACK.

IMPORTANT

The OAuth callback url for SmartThings Cloud is: https://api.smartthings.com/oauth/callback. However, in the above urlTemplate, the redirect_uri must have the URL encoded OAuth callback url: https%3A%2F%2Fapi.smartthings.com%2Foauth%2Fcallback.

Create the device in SmartThings Cloud

When your SmartThings Connector receives a list of devices from the third-party device cloud, the next step is to create these devices in SmartThings Cloud. Note that these devices are created at the user’s Location in SmartThings Cloud.

Here is an example of a POST request body to create a device, and the response back from SmartThings Cloud.

{
  "label": "Living room light",
  "locationId": "0c0b935d-0616-4441-a0bf-da7aeec3dc0a",
  "app": {
    "profileId": "6f5ea629-4c05-4a90-a244-cc129b0a80c3",
    "installedAppId": "6f5ea629-4c05-4a90-a244-cc129b0a80c3",
    "externalId": "Th13390"
  }
}
{
  "deviceId": "6f5ea629-4c05-4a90-a244-cc129b0a80c3",
  "name": "color.light.100x",
  "label": "color.light.100x",
  "deviceManufacturerCode": "010F-0B01-2002",
  "locationId": "0c0b935d-0616-4441-a0bf-da7aeec3dc0a",
  "components": [
    {
      "id": "main",
      "capabilities": [
        {
          "id": "switch"
        }
      ]
    }
  ],
  "app": {
    "installedAppId": "0c0b935d-0616-4441-a0bf-da7aeec3dc0a",
    "externalId": "Th13390",
    "profile": {
      "id": "user@example.com/thermostat.model1"
    }
  },
  "dth": {
    "deviceTypeId": "7b8514e6-230d-41cc-b3c2-512bca15abf0",
    "deviceTypeName": "x.com.samsung.da.fridge",
    "deviceNetworkType": "ZWAVE"
  },
  "type": "DTH"
}