Simple Smart Cloud Connector with Red Node

Hello,

I would like create a simple Smart Cloud Connector to connect a Red Node Device (on a RPI)
The purpose is to interface my Texecom Alarm with Smartthings

https://github.com/el3359/Simple-Smartthings-Connector-On-Red-Node

I have some incomprehension with the smartthings callback (I’m newbie with OAuth)

My Authorization Server is on Red Node

Step One:
My Authorization Server receive a request from Smartthings App for the association:

Request:
Red Node receive the request with Client ID+Secret ID + State (generated from Smartthings platform)+ redirect URI

Response from Red Node:
location =msg.payload.redirect_uri+"?code=trucmachinchose&state="+msg.payload.state;
Statuscode=303
where:
msg.payload.redirect_uri is the smartthing callback: https://c2c-eu.smartthings.com/oauth/callback
code is the code generated from Red Node
State is the sate from the Smartthings Request

Step One is ok, i think

Step Two:
Red Node receive a Token Request from Smarthings

Request From Smartthings to Red Node:
Request (Post) with Grant_Type, Code, Redirect_uri

Response From Red Node to Smartthings
Return a json with token, refresh token and expires
jsonresponse={
“access_token” : “cestmontoken”,
“token_type” : “Bearer”,
“expires_in” : “600”,
“refresh_token” : “cestmonrefreshtoken”,
“redirect_uri” : “https://c2c-eu.smartthings.com/oauth/callback
};

After that, the Smartthings App accept the association but with an error on the callbak function
I think i need to specify some parameter in the redirect-uri.

May you help me?

Tagging @nayelyz.

Sorry, i don’t understand.
Why do you specify Tagging?

Regards

@nayelyz is a SmartThings partner who has a better understanding of the new API, than most of us.

Otherwise you can look at this NodeRED project for inspiration:

node-red-contrib-smartthings - npm

This uses a SmartApp to connect your local NodeRed to the SmartThings hub.

1 Like

Thanks but i would simulate a device and not pilot the smartthing’s devices

For the moment, i can link to smartthings cloud connector but with an error on the callback.
Si i received discover et state request but i can not make a callback interactiob (i think)

Hello @Ej3359,

Can you share with me the complete log of the callback error, please?
From your description, I can see that you are missing the state parameter in your response to SmartThings. It should be similar to the example below:

{ 
    access_token: 'cestmontoken',
    expires_in: '600',
    refresh_token: 'cestmonrefreshtoken',
    state:'value received from SmartThings in step one',
    token_type: 'Bearer'
    redirect_uri : 'https://c2c-eu.smartthings.com/oauth/callback'
}

Make sure that after the grantAccessCallback, you request an Access Token to SmartThings using the code located in the callbackAuthentication, the Client ID and Client Secret (obtained in the developer Workspace). You will need that token to send stateCallbacks from your cloud.

Hello nayelyz

Thanks for your help. Now, i’ll received a grant access (Post Method on the my URL’s connector)

What is the next step to obtain the token:
1°) a response with status 200 on the Grant Callback Access.
2°) Make an Http post to https://c2c-eu.smartthings.com/oauth/token

and after, with the token, i can use the https://c2c-eu.smartthings.com/device/events with token to send the update of my device?

Regard

Hi @Ej3359,

You’re right. For number 2, make sure to follow the guidelines to obtain the Reciprocal Token.
The updates are sent to the stateCallback URL using the structure shown for the Device State Callback interaction.

2 Likes

Hello @nayelyz,

Thanks, that’s work fined! :slight_smile:

1 Like

Hello @nayelyz,

Do you know the way to Delete the service (my connector) in the Smartthings App?
I have delete my project in the Developer Workspace but i received request from Smartthings Cloud?

Regards

Sure! In the SmartThings app:

  1. Click on menu > settings.
  2. Find the option “Linked services” and enter.
  3. Then click on the button located in the top-right corner and select “Delete”.
  4. Choose the name of your Cloud connector and confirm.

This will also delete all the devices discovered using this connector.

Hello @nayelyz,

Thanks, I’m on IOS but that works with Android APP. I added the integrationDelete function on Red Node , it solde the problem

I can get the token and refresh the token to callback ST, but I’m having trouble renewing the refresh token.

When i make a request to https://c2c-eu.smartthings.com/oauth/token, i have this response:
{
“headers”: {
“schema”: “st-schema”,
“version”: “1.0”,
“interactionType”: “refreshAccessTokens”,
“requestId”: “AE8E579B-0E3A-46F3-93FA-486DDE8B4E4B”
},
“globalError”: {
“errorEnum”: “INVALID-TOKEN”,
“detail”: “refresh token is malformed or call is made to wrong callback URL”
}
}

My request:
{
“schema”:“st-schema”,
“version”:“1.0”,
“interactionType”:“refreshAccessTokens”,
“requestId”:“AE8E579B-0E3A-46F3-93FA-486DDE8B4E4B”}
{
“grantType”:“refresh_token”,
“clientId”:“xxxxxxxx-b062-4455-b572-860976571cda”,
“clientSecret”:“xxxxxxxxx070b759aa84d16af86a450a39753128f98b08e442f4c2304424b8160d7436b1e8c4418ccab4c5d23cf56e9d2e5d767b5721bdaa11977a4c0a8b091d091aa7759298d212e98838e96e46e139bfed1b183158b56c677dd805022af344c19e3026b9f4de6993012c15437c025576fd79b0a043ed2c7adb88026857b5d76d6ae63092645b5483f3d33fabaffb11339b40463ced8da4cc2940cf6a09914c05c8735313c94e4c871fd8d9a00d7a47f1491d1d9e5e613aa948699aaab3c474829e9fdd679d4d3a8469a0aa3d8ad86a4ea225503a9166054b1bfad5982c7aee5d3ef542e1db54a1fd04ffe95a131c3c63e2a928dc64cce47e80d77355194ae3”,
“refresh_token”:“xxxxxxciOiJIUzM4NCJ9.MDljM2FiYTEtNWNiMS00MTUwLWE0NzgtM2RkYzQwMDk5MzgwOk15IENsb3VkIENvbm5lY3RvciBWMQ._WPg2tu-2g4Grjoz2TMh5AofMlgnf84L2KcuMPLibxw3QRTOc8S_mI9l-_ojgfTl”
}
I checked the Client ID, Secret ID and refresh Token (164 cars), i don’t see any errors.

May you help me?

Your request is correct, I refreshed my AccessToken just fine.
I need to look over this, so, please send an email to build@smartthings.com, and include this information:

  • Complete logs of the request
  • App ID of the schema connector (e.g. viper_xxxx)
  • Last DateTime when you made the request

Hi,

I have send an email.

I have a question: Should I wait until the access token has expired before renewing the refresh token? or i can make before the expiration?

thanks! Now I see what happened, you wrote refresh_token instead of refreshToken. If you change that, the request will be ok.
Check this sample:

{
    "headers": {
        "schema": "st-schema",
        "version": "1.0",
        "interactionType": "refreshAccessTokens",
        "requestId": "abc-123-456"
    }, 
    "callbackAuthentication": {
        "grantType": "refresh_token",
        "clientId": "xxxxxx",
        "clientSecret": "xxxxxx",
        "refreshToken": "xxxxx"
    }
}

You don’t have to wait and the same refreshToken is valid until you delete the connector.

Thank’s, It’s ok