Skip to main content

OAuth with the third-party device cloud (oauth out to a third-party cloud)

When your SmartApp Connector receives the device list from the third-party device cloud with a GET request, the SmartApp 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 SmartApp Connector is being installed.

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.

{% textbox warning 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`.

{% endtextbox %}

Create the device in SmartThings Cloud#

When your SmartApp 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.

{% tabCodeBlocks %} {% codeblock REQUEST lang:plain %} { "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" } } {% endcodeblock %}

{% endtabCodeBlocks %}