Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //Example of getting the Auth credentials for the first time by directoring the
            //user to the fitbit site to get a PIN. 
            var consumerKey = "YOUR_CONSUMER_KEY_HERE";
            var consumerSecret = "YOUR_CONSUMER_SECRET_HERE";
            var requestTokenUrl = "http://api.fitbit.com/oauth/request_token";
            var accessTokenUrl = "http://api.fitbit.com/oauth/access_token";
            var authorizeUrl = "http://www.fitbit.com/oauth/authorize";

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

            RequestToken token = a.GetRequestToken();

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

            Process.Start(url);

            Console.WriteLine("Enter the verification code from the website");
            var pin = Console.ReadLine();

            var credentials = a.GetAuthCredentialFromPin(pin, token);


            //If you already have your credentials stored then rather than getting the users PIN again
            //you could just start here
            var fitbit = new FitbitClient(consumerKey, consumerSecret, credentials.AuthToken, credentials.AuthTokenSecret);
            var profile = fitbit.GetUserProfile();
            Console.WriteLine("Your last weight was {0}",profile.Weight);

            Console.ReadLine();
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Example of getting the Auth credentials for the first time by directoring the
            //user to the fitbit site to get a PIN.
            // GitHub test from Andy
            var consumerKey = "b3d888281c9b4e098c26c6d1ce4e9d57";
            var consumerSecret = "dc6f84c589c341789967b57e83084572";
            var requestTokenUrl = "http://api.fitbit.com/oauth/request_token";
            var accessTokenUrl = "http://api.fitbit.com/oauth/access_token";
            var authorizeUrl = "http://www.fitbit.com/oauth/authorize";

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

            System.Diagnostics.Process.Start(url);

            Console.WriteLine("Enter the verification code from the website");
            var pin = verificationCodeTextBox.Text;

            var credentials = a.GetAuthCredentialFromPin(pin);

            //If you already have your credentials stored then rather than getting the users PIN again
            //you could just start here
            var fitbit = new FitbitClient(consumerKey, consumerSecret, credentials.AuthToken, credentials.AuthTokenSecret);
            var profile = fitbit.GetUserProfile();
            Console.WriteLine("Your last weight was {0}", profile.Weight);

            Console.ReadLine();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        //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");

        }
Ejemplo n.º 5
0
        public AuthenticationTests()
        {
            authenticator = new Fitbit.Api.Authenticator(Configuration.ConsumerKey,
                                            Configuration.ConsumerSecret,
                                            "http://api.fitbit.com/oauth/request_token",
                                            "http://api.fitbit.com/oauth/access_token",
                                            "http://api.fitbit.com/oauth/authorize");

        }
Ejemplo n.º 6
0
 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();
 }
Ejemplo n.º 7
0
        private static AuthCredential GetLoginCredentials()
        {
            const string requestTokenUrl = "http://api.fitbit.com/oauth/request_token";
            const string accessTokenUrl = "http://api.fitbit.com/oauth/access_token";
            const string authorizeUrl = "http://www.fitbit.com/oauth/authorize";

            var a = new Authenticator(CONSUMER_KEY, CONSUMER_SECRET, requestTokenUrl, accessTokenUrl, authorizeUrl);
            var url = a.GetAuthUrlToken();

            Process.Start(url);

            Console.WriteLine("Enter the verification code from the website");
            var pin = Console.ReadLine();

            var credentials = a.GetAuthCredentialFromPin(pin);
            return credentials;
        }
Ejemplo n.º 8
0
        //
        // GET: /FitbitAuth/
        // Setup - prepare the user redirect to Fitbit.com to prompt them to authorize this app.
        public ActionResult Authorize()
        {

            //make sure you've set these up in Web.Config under <appSettings>:
            string ConsumerKey = ConfigurationManager.AppSettings["FitbitConsumerKey"];
            string ConsumerSecret = ConfigurationManager.AppSettings["FitbitConsumerSecret"];


            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");
            string authUrl = authenticator.GetAuthUrlToken();


            return Redirect(authUrl);
        }
Ejemplo n.º 9
0
        static AuthCredential Authenticate()
        {
            var requestTokenUrl = "http://api.fitbit.com/oauth/request_token";
            var accessTokenUrl = "http://api.fitbit.com/oauth/access_token";
            var authorizeUrl = "http://www.fitbit.com/oauth/authorize";

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

            RequestToken token = a.GetRequestToken();

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

            Process.Start(url);

            Console.WriteLine("Enter the verification code from the website");
            var pin = Console.ReadLine();

            var credentials = a.GetAuthCredentialFromPin(pin, token);
            return credentials;
        }
Ejemplo n.º 10
0
        //
        // GET: /FitbitAuth/
        // Setup - prepare the user redirect to Fitbit.com to prompt them to authorize this app.
        public ActionResult Authorize()
        {

            //make sure you've set these up in Web.Config under <appSettings>:
            string ConsumerKey = ConfigurationManager.AppSettings["FitbitConsumerKey"];
            string ConsumerSecret = ConfigurationManager.AppSettings["FitbitConsumerSecret"];


            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");
            RequestToken token = authenticator.GetRequestToken();
            Session.Add("FitbitRequestTokenSecret", token.Secret.ToString()); //store this somehow, like in Session as we'll need it after the Callback() action

            //note: at this point the RequestToken object only has the Token and Secret properties supplied. Verifier happens later.

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


            return Redirect(authUrl);
        }
Ejemplo n.º 11
0
        private void FitBitLogin_Load(object sender, EventArgs e)
        {
            //make sure you've set these up in Web.Config under <appSettings>:
            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");
            string authUrl = authenticator.GetAuthUrlToken();

            webBrowser1.Url = new Uri(authUrl);
            //Final step. Take this authorization information and use it in the app
            dash.oauth_token = authUrl.Substring(authUrl.IndexOf("oauth_token=") +12);
        }