/// <summary> /// Part 1 of authorisation. Pass user to fitbit to authorise app (fitbit client id/secret required which are stored in web.config) /// </summary> /// <returns></returns> public ActionResult Authorize() { var authenticator = new OAuth2Helper(FitbitHelper.GetFitbitAppCredentials(), Request.Url.GetLeftPart(UriPartial.Authority) + "/Fitbit/Callback"); string[] scopes = new string[] { "profile", "heartrate", "nutrition", "sleep", "weight" }; string authUrl = authenticator.GenerateAuthUrl(scopes, null); return(Redirect(authUrl)); }
public ActionResult Login() { var authenticator = new OAuth2Helper(_appCredentials, ConfigurationManager.AppSettings["BaseUrl"] + "/band/callback"); string[] scopes = new string[] { "profile" }; string authUrl = authenticator.GenerateAuthUrl(scopes, null); return(Redirect(authUrl)); }
public object GetAuthCode(string code) { var authorization = "Basic Y2xpZW50X2lkOjljZmZlMzg2ZjFiZGQ5NjZjZmZhOTY1OTJhN2NhYzky"; var contenttype = "application/x-www-form-urlencoded"; var redirectURI = "http://localhost:50195/api/fitbit/callback"; //var redirectURI = "https://testfit.azurewebsites.net/api/fitbit/callback"; var queryParams = "client_id=" + OAuthClientID + "&grant_type=authorization_code&redirect_uri=" + redirectURI + "&code=" + code; var appCredentials = new FitbitAppCredentials() { ClientId = ConfigurationManager.AppSettings["FitbitClientId"], ClientSecret = ConfigurationManager.AppSettings["FitbitClientSecret"] }; //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 var authenticator = new OAuth2Helper(appCredentials, redirectURI); string[] scopes = new string[] { "profile", "activity", "heartrate", "location", "nutrition", "settings", "sleep", "social", "weight" }; string authUrl = authenticator.GenerateAuthUrl(scopes, null); return(Redirect(authUrl)); /* * HttpClient client = new HttpClient(); * client.BaseAddress = new Uri(AccessTokenRefreshURI); * * client.DefaultRequestHeaders.Accept * .Add(new MediaTypeWithQualityHeaderValue(contenttype));//ACCEPT header * client.DefaultRequestHeaders.Add("Authorization", authorization); * * HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, queryParams); * * client.SendAsync(request) * .ContinueWith(responseTask => * { * var response = responseTask.Result; * return response; * }); * * return null; */ }
private void Load() { try { OAuth2Helper authenticator = new OAuth2Helper("227H9T", "74e4a047fce979dd36a0edbd626c3939", "http://Miriot.suismoi.fr"); string[] scopes = new[] { "profile", "weight" }; string authUrl = authenticator.GenerateAuthUrl(scopes, null); WebView browser = new WebView(); browser.Height = 300; browser.Width = 300; browser.Source = new Uri(authUrl); browser.DefaultBackgroundColor = Colors.Black; MainGrid.Children.Add(browser); browser.NavigationStarting += async(s, args) => { if (args.Uri.OriginalString.Contains("code=")) { var code = args.Uri.Query.Replace("?code=", ""); AccessToken = await authenticator.ExchangeAuthCodeForAccessTokenAsync(code); AccessToken = await authenticator.RefreshToken(AccessToken.RefreshToken); MainGrid.Children.Remove(browser); try { var w = await GetWeightAsync(DateTime.Now, null); Value.Text = $"{w.Weight.First().Weight}kg"; } catch (Exception ex) { // Access denied ? Debug.WriteLine(ex.Message); } } }; } catch (Exception ex) { // Something went wrong Debug.WriteLine(ex.Message); } }
public IHttpActionResult Authorize() { var appCredentials = new FitbitAppCredentials() { ClientId = clientId, ClientSecret = clientSecret }; 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 controller's result method var authenticator = new OAuth2Helper(appCredentials, $"{Request.RequestUri.GetLeftPart(UriPartial.Authority)}/fitbit/{nameof(RegistrationResult).ToLowerInvariant()}"); string[] scopes = Enum.GetValues(typeof(FitbitAuthScope)).Cast <FitbitAuthScope>().Select(x => x.ToString().ToLowerInvariant()).ToArray(); string authUrl = authenticator.GenerateAuthUrl(scopes, null); return(Redirect(authUrl)); }
// // GET: /FitbitAuth/ // Setup - prepare the user redirect to Fitbit.com to prompt them to authorize this app. public ActionResult Authorize() { var appCredentials = new FitbitAppCredentials() { ClientId = ConfigurationManager.AppSettings["FitbitClientId"], ClientSecret = ConfigurationManager.AppSettings["FitbitClientSecret"] }; //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 var authenticator = new OAuth2Helper(appCredentials, Request.Url.GetLeftPart(UriPartial.Authority) + "/Fitbit/Callback"); string[] scopes = new string[] { "profile", "weight", "activity", "sleep" }; string authUrl = authenticator.GenerateAuthUrl(scopes, null); return(Redirect(authUrl)); }
// // GET: /Authorize/ // Setup - prepare the user redirect to Fitbit.com to prompt them to authorize this app. public async Task <ActionResult> Authorize() { //make sure you've set these up in Web.Config under <appSettings>: var appCredentials = new FitbitAppCredentials() { ClientId = ConfigurationManager.AppSettings["FitbitConsumerKey"], ClientSecret = ConfigurationManager.AppSettings["FitbitConsumerSecret"] }; //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 var authenticator = new OAuth2Helper(appCredentials, Request.Url?.GetLeftPart(UriPartial.Authority) + "/Fitbit/Callback"); string[] scopes = new string[] { "profile" }; Session["FitbitAuthenticator"] = authenticator; //note: at this point the RequestToken object only has the Token and Secret properties supplied. Verifier happens later. string authUrl = authenticator.GenerateAuthUrl(scopes); return(Redirect(authUrl)); }
public HttpResponseMessage Authorize() { var appCredentials = new BandAppCredentials() { ClientId = ConfigurationManager.AppSettings["BandClientId"], ClientSecret = ConfigurationManager.AppSettings["BandClientSecret"] }; _credentials = 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 //var authenticator = new OAuth2Helper(appCredentials, Request.Url.GetLeftPart(UriPartial.Authority) + "/band/callback"); var authenticator = new OAuth2Helper(appCredentials, ConfigurationManager.AppSettings["BaseUrl"] + "/api/band/callback"); string[] scopes = new string[] { "profile" }; string authUrl = authenticator.GenerateAuthUrl(scopes, null); using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })) { client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("PostmanRuntime", "7.3.0")); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*")); HttpResponseMessage response = client.GetAsync(authUrl).Result; if (response.IsSuccessStatusCode) { return(response); } return(response); return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } }