Authorization and Web Services consuming from C# application


(Jorge) #1

Hi all,

I’m new in the smartthings development, starting this week, but very excited discovering the IoT world :wink:

Based on several examples, i created my first smartthing app to control a small demo lab (switches and presence sensors).

With the defined Web Services methods, for example, i can switch on / off my devices through web browser call (an more actions for additional devices), but only in a logged session scope.

I’m going beyond, developing a C# application, and i want to automate the authentication process to allow the application execute REST API call to that EndPoint Web Services Methods without end-user interaction. Is it possible to avoid the Login Page prompting the user for credentials?
I mean, is it possible that my application stores the user & password, and the ClientID and SecretID to authenticate with the EndPoint using Oauth?

I have found several post related with the OAuth auth process, for example:

Based on this example, a redirect_uri is requiered. is it correct? Can i use a HTTPClient to GET the request and store the “code” and “access_token” to make the authentication in my app scope?

Thanks in advance!

(joe) #2

I have a C# web app that steps through the oauth process and saves the info so it can be used in subsequent calls. It uses a web page on localhost so the redirection after you authorize the app via smart things works. That page will save off the auth keys into a local file, get information about endpoints, etc. Check out the oauthcontroller module in this repository for an example of how it works:

(Joshua Lyon ( Dashboard)) #3

Yes, the OAuth token can be stored and is the intended use of OAuth.

As an alternative to including a simple webserver in the app, you could run the OAuth workflow inside a webview and capture the OAuth code when the redirect happens (assuming the app has some sort of UI and is not a background service).

(Jorge) #4

Thank you so much for your responses, @joe64 and @joshua_lyon.

Few weeks ago i finished the Auth process to store the issued tocken on local App store, avoiding the user to retype his credentials.

These days I am going beyond, acomplised the improvement of that application with UI based commands and with voice command integration. Now, i can manage my connected devices from my virtual personal assistance, with multi-device support!

The power of the Smartthings IoT Platform is amazing!!

(baboucarr) #5

Hi everyone, I am also new to smartThings community and wanting to consume the web services api from a C# application as well. I was able to test the Get using HttpClient but getting stuck at performing a Put request. @joe64, from your description above, looks like your app could lead me to the right direction but your GitHub link is currently broken. Anyway you can point me to the code. Or if anyone has a good way of making PUT request, that will be great.


(joe) #6

(baboucarr) #7

Great. thanks a lot. very detailed and informative code. Good place to start my guide.