Currently I’m developing a Windows Service App. How can I implement OAuth2 flow that can refresh automatically daily? I tried to create Automation App in Developer Workspace but unfortunately it requires WebHook Endpoint which not applicable to desktop app:
You need an API-ONLY type of app, and the one you created in the Developer Workspace won’t work because it’s not the correct type. I’m sharing the steps below to help you create the right app.
The option to create OAuth integrations cannot be found in the Developer Workspace.
You need to use the SmartThings CLI to create this type of app
Then, you need to start the OAuth 2.0 process which consists on:
The Access Token you get expires in 24 hours.
The Refresh Token expires in 29 days if not used. We suggest you refresh the token before this time, otherwise, you’ll lose the Refresh token and the User will need to re-authorize.
NOTE: Remember the OAuth integration has alimit of 500 installations by default. Each time a user authorizes access to one of his/her locations, it will count as 1 installation. This means, if a user has 3 locations and authorizes access to each of them, he/she will use 3 installations.
To refresh the Access Token, you need to use the same endpoint but the grant_type is different, here’s an example about this:
Subscriptions require having a targetURL registered in the app because that’s where you’ll receive the new events.
This will also trigger a CONFIRMATION request (similar to a SmartApp) which means you need to verify the app by making a GET request to that URL to start receiving the events.