Consuming smartapp from C# desktop application


(Gil Hoffman) #1

Hi guys

I’m trying to consume smartapp with oauth from c# desktop application.
Authenticating via curl and consuming via browser worked fine.

I’ve tried several ways:

  1. via Microsoft.oswin - But I couldn’t get to authenticate.
  2. via regular process start: authentication went well, but I failed to retrieve the json’s via httpRequests.
    (2) is also ugly because of the authentication method.

Anyone tried this? Your ideas, example, etc …


(Kevin) #2

This might not be the best way to implement it, but it should work.

If you enable OAuth and generate the Access Token through the SmartApp that SmartApp will have a public url you can access from anywhere without being authenticated.

You can use the mappings in the SmartApp to specify methods to execute based on the url. You can pass information into that method using parameters in the url of a get request or by extracting the json data from a post request.

From that method you can use render to return html and I believe you can also use it to return json, but I haven’t tested that.

If you can’t return json from that method you could use that method to post the information to a public url or use sendhubaction to post it back to the computer on your local network.

The “mappings” section and methods that start with “api_” in the 2 SmartApps below provide examples of everything mentioned above.

Simple Device Viewer accepts information passed through get requests and uses render to return html.

Simple Event Logger parses json from a post request and also posts json to an external url.


(Gil Hoffman) #3

Thanks
Isn’t creating a token from inside the smartapp can effect remote security?
What is the public address created for ‘createApiToken’ method in use in that code?
Will I be able to access from httpWebRequest (C# call)?
I intend to write a wpf application controlling my home and alarm, that will execute in windows tablet in several locations in my house. Security for that kind of smartapp is critical.


(Kevin) #4

The public url contains the application id and the unique token you generate from within the SmartApp.

If you install multiple instances of the SmartApp they’ll all have different urls and you can change the url at any time by regenerating the access token.

I think the security risk is low as long as you don’t give out the url or access it from a public computer or network.

The url returns a response just like any other website so you should be able to use httpWebRequest.


(Gil Hoffman) #5

I think I’ll go with that solution. Can’t wait for this to work.
Thank you.