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")); }
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()); }