Skip to content

Breaking Change on 1 24 2014 as a result of OAuth update in Fitbit API

Aaron Coleman edited this page Jan 24, 2014 · 11 revisions

In order to correct the library to be in compliance with the Fitbit API Update (https://groups.google.com/forum/#!topic/fitbit-api/ii4pUt4uTNM) and ensure the code readability breaking changes to the OAuth dance were introduced. Here is how to update your code to use the new library:

Web Apps (see SampleWebMVC)

Authorize step (Authrorize() in FitbitController.cs):

Where previously you did:

string authUrl = authenticator.GetAuthUrlToken();

Do this:

RequestToken token = authenticator.GetRequestToken();

//store this somehow, like in Session as we'll need it after the Callback() action
Session.Add("FitbitRequestTokenSecret", token.Secret.ToString()); 
            
//note: at this point the RequestToken object only has the Token and Secret properties supplied. Verifier happens later.

string authUrl = authenticator.GenerateAuthUrlFromRequestToken(token, true);

After user authenticates and Callback (Callback() in FitbitController.cs)

Where previously you did:

string OAuthToken = Request.Params["oauth_token"];
string OAuthVerifier = Request.Params["oauth_verifier"];`

string ConsumerKey = ConfigurationManager.AppSettings["FitbitConsumerKey"];
string ConsumerSecret = ConfigurationManager.AppSettings["FitbitConsumerSecret"];


//create the Authenticator object
Fitbit.Api.Authenticator authenticator = new Fitbit.Api.Authenticator(ConsumerKey,
                                                                                    ConsumerSecret,
                                                                                    "http://api.fitbit.com/oauth/request_token",
                                                                                    "http://api.fitbit.com/oauth/access_token",
                                                                                    "http://api.fitbit.com/oauth/authorize");

AuthCredential credential = authenticator.ProcessApprovedAuthCallback(OAuthToken, OAuthVerifier);

Do this:

RequestToken token = new RequestToken();
token.Token = Request.Params["oauth_token"];
token.Secret = Session["FitbitRequestTokenSecret"].ToString();
token.Verifier = Request.Params["oauth_verifier"];

string ConsumerKey = ConfigurationManager.AppSettings["FitbitConsumerKey"];
string ConsumerSecret = ConfigurationManager.AppSettings["FitbitConsumerSecret"];

//this is going to go back to Fitbit one last time (server to server) and get the user's permanent auth credentials

//create the Authenticator object
Fitbit.Api.Authenticator authenticator = new Fitbit.Api.Authenticator(ConsumerKey,
                                                                                    ConsumerSecret,
                                                                                    "http://api.fitbit.com/oauth/request_token",
                                                                                    "http://api.fitbit.com/oauth/access_token",
                                                                                    "http://api.fitbit.com/oauth/authorize");


//execute the Authenticator request to Fitbit
AuthCredential credential = authenticator.ProcessApprovedAuthCallback(token);

Desktop Apps

Authentication step (Main() in Program.cs)

Where previously you did :

var a = new Authenticator(consumerKey, consumerSecret,requestTokenUrl,accessTokenUrl,authorizeUrl);
var url = a.GetAuthUrlToken();

Process.Start(url);

Do this:

var a = new Authenticator(consumerKey, consumerSecret,requestTokenUrl,accessTokenUrl,authorizeUrl);

RequestToken token = a.GetRequestToken();

var url = a.GenerateAuthUrlFromRequestToken(token, false);

Process.Start(url);