1 Replies - 2251 Views - Last Post: 29 July 2013 - 08:57 AM Rate Topic: -----

#1 y_chen   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-July 13

Automate OAuth2 authentication

Posted 25 July 2013 - 12:46 AM

I'm working with measuring vital signs devices. The manufacturer is iHealth. These connect with a smartphone where is installed an app that when you are logged in with your account it sends the measurements to their server. I have to connect to this server and extract the datas from many accounts but at the moment I will be satisfy to extract only mine. To do this iHealth provides a Sandbox like example that you can download at this url: Attached File  SandboxAPISample.zip (81.81K)
Number of downloads: 65 .

In this example all the needed variables (client_id, client_secret, redirect_url etc) are set up in the ConnectToiHealthlabs.cs class.

When you start the project the page GetStarted.aspx is loaded and only a button appears. By clicking the button the follow method is called from ConnectToiHealthlabs.cs class:

public void GetCode()
        string url = url_authorization
            + "?client_id=" + client_id
            + "&response_type=" + response_type_code
            + "&redirect_uri=" + redirect_uri
            + "&APIName=" + APIName_BP + " " + APIName_Weight;


The url where it redirects is
http://sandboxapi.ihealthlabs.com/api/OAuthv2/userauthorization.ashx?client_id=e4dce2f7027044e0a6ce82ef44d27e23&response_type=code&redirect_uri=http://localhost:9201/TestPage.aspx&APIName=OpenApiBP OpenApiWeight

So you will arrive to the page

Now you can authenticate with the sandbox credentials:

username: [email protected]

Password: 111111

If the credentials are right you will be redirected to TestPage.aspx where this method is called:

public bool GetAccessToken(string code, string client_para, HttpContext httpContext)
        string url = url_authorization
        + "?client_id=" + client_id
        + "&client_secret=" + client_secret
        + "&client_para=" + client_para
        + "&code=" + code
        + "&grant_type=" + grant_type_authorization_code
        + "&redirect_uri=" + redirect_uri;

        string ResultString = this.HttpGet(url);

        if (ResultString.StartsWith("{\"Error\":"))
            this.Error = JsonDeserializ<ApiErrorEntity>(ResultString);
            return false; 
            AccessTokenEntity accessToken = this.JsonDeserializ<AccessTokenEntity>(ResultString);
            httpContext.Session["token"] = accessToken;
            return true;

The result url is

So if everything is correct you can see a button to download BP data (url:

download weight data (url:

and refresh token (url:

In this example it databinds a repeater with the list that returns DownloadBPData and DownloadWeightData methods to show the values in the page.

My goal is to arrive these two lists without open popups and without manual authentications scheduling the update speed.

All in a log like page:

24/07/2013 12:00 - Found new data for user ABC

24/07/2013 11:30 - Found new data for user XYZ

24/07/2013 11:00 - etc...

But I really don't know where to start.

The only documentation that I have is the following file: Attached File  Open API Protocol.zip (459.46K)
Number of downloads: 632

The url in the sandbox project are differents from the server where I have to connect I found a lot of OAuth2 libraries but all the examples are for Facebook, Twitter etc.

Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Automate OAuth2 authentication

#2 y_chen   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-July 13

Re: Automate OAuth2 authentication

Posted 29 July 2013 - 08:57 AM

No one can help me?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1