//Final step. Take this authorization information and use it in the app
        public ActionResult Callback()
        {
            string OAuthToken    = Request.Params["oauth_token"];
            string OAuthVerifier = 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(OAuthToken, OAuthVerifier);

            //here, we now have everything we need for the future to go back to Fitbit's API (STORE THESE):
            //  credential.AuthToken;
            //  credential.AuthTokenSecret;
            //  credential.UserId;

            // For demo, put this in the session managed by ASP.NET
            Session["FitbitAuthToken"]       = credential.AuthToken;
            Session["FitbitAuthTokenSecret"] = credential.AuthTokenSecret;
            Session["FitbitUserId"]          = credential.UserId;

            return(RedirectToAction("Index", "Home"));
        }
Example #2
0
        static void Main(string[] args)
        {
            Authenticator authorizer = new Authenticator("a57cf7b1e3f34405a9d80b9e520c50ec", "53d618141c5c4b6f929506ef41d9611f",
                "http://api.fitbit.com/oauth/request_token",
                "http://api.fitbit.com/oauth/access_token",
                "http://www.fitbit.com/oauth/authorize");

            string url = authorizer.GetAuthUrlToken();

            Console.WriteLine("Authorization URL: " + url);

            string tempAuthToken;
            string verifier;

            Console.Write("oauth_token: ");
            tempAuthToken = Console.ReadLine();

            Console.Write("oauth_verifier: ");
            verifier = Console.ReadLine();

            AuthCredential credential = authorizer.ProcessApprovedAuthCallback(tempAuthToken, verifier);

            Console.WriteLine("access_token: " + credential.AuthToken);
            Console.WriteLine("access_secret: " + credential.AuthTokenSecret);

            Console.ReadLine();
        }
        //Final step. Take this authorization information and use it in the app
        public ActionResult Callback()
        {
            string OAuthToken = Request.Params["oauth_token"];
            string OAuthVerifier = 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(OAuthToken, OAuthVerifier);

            //here, we now have everything we need for the future to go back to Fitbit's API (STORE THESE):
            //  credential.AuthToken;
            //  credential.AuthTokenSecret;
            //  credential.UserId;

            // For demo, put this in the session managed by ASP.NET
            Session["FitbitAuthToken"] = credential.AuthToken;
            Session["FitbitAuthTokenSecret"] = credential.AuthTokenSecret;
            Session["FitbitUserId"] = credential.UserId;
            
            return RedirectToAction("Index", "Home");

        }
 private void button1_Click(object sender, EventArgs e)
 {
     string ConsumerKey = "84c3fd4c63f04ab88dff2ec80e7690a9";
     string ConsumerSecret = "5d8fe7b6849f4b0b8bf10261038ed836";
     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");
     dash.oauth_verifier = textBox1.Text.ToString();
     AuthCredential credential = authenticator.ProcessApprovedAuthCallback(dash.oauth_token, dash.oauth_verifier);
     dash.oauth_token = credential.AuthToken;
     dash.oauth_token_secret = credential.AuthTokenSecret;
     dash.user_id = credential.UserId;
     this.Close();
 }