Exemple #1
0
        public ActionResult Authorize()
        {
            var appCredentials = new WithingsAppCredentials()
            {
                ConsumerKey    = ConfigurationManager.AppSettings["WithingsConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["WithingsConsumerSecret"]
            };

            //make sure you've set these up in Web.Config under <appSettings>:

            Session["AppCredentials"] = appCredentials;

            //Provide the App Credentials. You get those by registering your app at dev.fitbit.com
            //Configure Fitbit authenticaiton request to perform a callback to this constructor's Callback method

            ViewBag.Response = appCredentials;
            return(View());
        }
Exemple #2
0
        public async Task <ActionResult> AccessTokenFlow()
        {
            //var accessToken = Request.QueryString["oauth_token"].ToString();

            //List<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>();
            //parameters.Add(new KeyValuePair<string, string>("oauth_token", accessToken));

            var appCredentials = new WithingsAppCredentials()
            {
                ConsumerKey    = ConfigurationManager.AppSettings["WithingsConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["WithingsConsumerSecret"]
            };

            //saving consumerKey and Secret into session
            Session["AppCredentials"] = appCredentials;

            //oAuthVerifier taken from url to string to be made into a Key Value pair
            var oAuthVerifier = Request.QueryString["oauth_verifier"].ToString();
            List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >();

            parameters.Add(new KeyValuePair <string, string>("oauth_verifier", oAuthVerifier));

            //Using AppCredentials in session into instanticiating WithingsAppAUthenticator
            var withingsAppConstructor = new WithingsAppAuthenticator((WithingsAppCredentials)Session["AppCredentials"]);

            //Calling request token from previous method to inject into new AccessToken Call
            var requestTokenSession = Session["requestToken"] as RequestToken;

            //Awaiting Method from WithingsAppAuthenticator Class to return
            AccessToken accessTokenResponse = await withingsAppConstructor.AccessTokenFlow(requestTokenSession, oAuthVerifier);

            Session["accessToken"] = accessTokenResponse;

            string userId = Request.QueryString["userid"];

            Session["UserId"] = userId;

            WithingsClient client = new WithingsClient(appCredentials, accessTokenResponse);

            return(View("AccessTokenFlow"));
        }
Exemple #3
0
        public async Task <ActionResult> GetWithingsClient(string currentDate, string userid)
        {
            var accessToken    = Session["accessToken"] as AccessToken;
            var appCredentials = new WithingsAppCredentials()
            {
                ConsumerKey    = ConfigurationManager.AppSettings["WithingsConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["WithingsConsumerSecret"]
            };

            var userId = Session["UserId"].ToString();

            string date = DateTime.Now.ToString("yyyy-MM-dd");

            WithingsClient client = new WithingsClient(appCredentials, accessToken);

            var response = await client.GetDayActivityAsync(date, userId);

            ViewBag.ResponseData = response;

            return(View("GetWithingsClient"));
        }
Exemple #4
0
        public async Task <ActionResult> CallBack()
        {
            WithingsAppCredentials appCredentials = (WithingsAppCredentials)Session["AppCredentials"];


            var withingsAppConstructor = new WithingsAppAuthenticator((WithingsAppCredentials)Session["AppCredentials"]);

            RequestToken requestTokenResponse = await withingsAppConstructor.GetRequestTokenAsync();

            ViewBag.displayRequest = requestTokenResponse;

            Session["requestToken"] = requestTokenResponse;
            //Will appear as a link on the webpage after requestToken is passed
            var redirectUrl = withingsAppConstructor.GenerateAuthUrlFromRequestToken(requestTokenResponse);

            ViewBag.RedirectUrl = redirectUrl;
            ViewBag.RedirectUrl.ToString();

            // "~/View/Withings/CallBack.aspx"


            return(View());
        }
Exemple #5
0
        public async Task <ActionResult> GetWithingsBodyMeas(string userid, string devType)
        {
            var accessToken    = Session["accessToken"] as AccessToken;
            var appCredentials = new WithingsAppCredentials()
            {
                ConsumerKey    = ConfigurationManager.AppSettings["WithingsConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["WithingsConsumerSecret"]
            };

            var userId     = Session["UserId"].ToString();
            var deviceType = "4";


            WithingsClient client = new WithingsClient(appCredentials, accessToken);

            var response = await client.GetBodyMeasureAsync(userId, deviceType);

            ViewBag.BloodPressueResponse = response;



            return(View("GetWithingsBodyMeas"));
        }