Example #1
0
        private void getC2GAccessToken(string[] tokenData)
        {
            var car2GoGetTokenEndpoint = "https://www.car2go.com/api/accesstoken";

            var oauthRequest = new OAuthRequest() {
                CallbackUrl = "oob",
                ConsumerKey = FreeCarsCredentials.Car2Go.ConsumerKey,
                ConsumerSecret = FreeCarsCredentials.Car2Go.SharedSecred,
                Method = "GET",
                RequestUrl = car2GoGetTokenEndpoint,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                Token = tokenData[0],
                TokenSecret = (string)App.GetAppSetting("car2go.oauth_token_secret"),
                //TokenSecret = tokenData[1],
                Type = OAuthRequestType.AccessToken,
                Verifier = tokenData[1],
                Version = "1.0",
            };
            var requestParameters = oauthRequest.GetAuthorizationQuery();
            var requestUrl = new Uri(car2GoGetTokenEndpoint + "?" + requestParameters, UriKind.Absolute);

            var webClient = new WebClient();
            webClient.DownloadStringCompleted += (client, arguments) => {
                if (null != arguments.Error) {
                    MessageBox.Show(Strings.SettingsPageCar2GoAuthFailed);
                    return;
                }
                var results = arguments.Result.Split(new char[] { '&' }, StringSplitOptions.None);
                App.SetAppSetting("car2go.oauth_token", results[0].Split(new char[] { '=' })[1]);
                App.SetAppSetting("car2go.oauth_token_secret", results[1].Split(new char[] { '=' })[1]);
                App.SetAppSetting("car2go.oauth_token_timestamp", DateTime.UtcNow);
                CheckCar2GoApiAccess();
            };
            webClient.DownloadStringAsync(requestUrl);
        }
Example #2
0
        private void connectCar2Go()
        {
            var car2GoGetTokenEndpoint = "https://www.car2go.com/api/reqtoken";
            var oauthRequest = new OAuthRequest {
                CallbackUrl = "oob",
                ConsumerKey = FreeCarsCredentials.Car2Go.ConsumerKey,
                ConsumerSecret = FreeCarsCredentials.Car2Go.SharedSecred,
                Method = "GET",
                RequestUrl = car2GoGetTokenEndpoint,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                Type = OAuthRequestType.RequestToken,
                Version = "1.0",
            };
            var requestParameters = oauthRequest.GetAuthorizationQuery();
            var requestUrl = new Uri(car2GoGetTokenEndpoint + "?" + requestParameters, UriKind.Absolute);

            var webClient = new WebClient();
            webClient.DownloadStringCompleted += delegate(object client, DownloadStringCompletedEventArgs arguments) {
                string[] results = { };
                if (null != arguments.Error) {
                    return;
                }
                var authorizeUrl = new Uri("https://www.car2go.com/api/authorize?" + arguments.Result, UriKind.Absolute);
                results = arguments.Result.Split(new string[] { "&" }, StringSplitOptions.None);
                App.SetAppSetting("car2go.oauth_token_secret", results[1].Split(new char[] { '=' })[1]);
                App.SetAppSetting("car2go.oauth_request_token", results[0].Split(new char[] { '=' })[1]);
                //(string)IsolatedStorageSettings.ApplicationSettings["current_map_city"]
                if (App.IsCertified) {
                    c2gAuthBrowser.Dispatcher.BeginInvoke(() => {
                        c2gAuthBrowser.Visibility = Visibility.Visible;
                        c2gAuthBrowser.Navigate(authorizeUrl);
                    });
                } else {
                    verifierPanel.Visibility = Visibility.Visible;
                    var authBrowserTask = new WebBrowserTask {
                        Uri = authorizeUrl,
                    };
                    c2gScrollViewer.ScrollToVerticalOffset(c2gScrollViewer.ActualHeight);
                    authBrowserTask.Show();
                }
            };
            webClient.DownloadStringAsync(requestUrl);
        }
 public void verifyUrl(string url)
 {
     var qsParams = HttpUtility.ParseQueryString(url);
     var token = qsParams.Get("oauth_token");
     var verifier = qsParams.Get("oauth_verifier");
     OAuthRequest client = new OAuthRequest()
     {
         Method = "GET",
         Type = OAuthRequestType.AccessToken,
         SignatureMethod = OAuthSignatureMethod.HmacSha1,
         ConsumerKey = this.consumerKey,
         ConsumerSecret = this.consumerSecret,
         RequestUrl = "https://api.shapeways.com/oauth1/access_token/v1",
         Version = "1.0a",
         Realm = "shapeways.com",
         TokenSecret = this.OAuthSecret,
         Token = token,
         Verifier = verifier,
     };
     string auth = client.GetAuthorizationQuery();
     string requestUrl = client.RequestUrl + "?" + auth;
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
     string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
     var result = HttpUtility.ParseQueryString(content);
     this.OAuthToken = result.Get("oauth_token");
     this.OAuthSecret = result.Get("oauth_token_secret");
 }
Example #4
-1
 public String connect()
 {
     OAuthRequest client = new OAuthRequest()
     {
         Method = "GET",
         Type = OAuthRequestType.RequestToken,
         SignatureMethod = OAuthSignatureMethod.HmacSha1,
         ConsumerKey = this.consumerKey,
         ConsumerSecret = this.consumerSecret,
         RequestUrl = "https://api.shapeways.com/oauth1/request_token/v1",
         Version = "1.0a",
         Realm = "shapeways.com",
         CallbackUrl = this.callback,
     };
     string auth = client.GetAuthorizationQuery();
     string url = client.RequestUrl + "?" + auth;
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
     string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
     var result = HttpUtility.ParseQueryString(content);
     var authUrl = result.Get("authentication_url");
     this.OAuthToken = result.Get("oauth_token");
     this.OAuthSecret = result.Get("oauth_token_secret");
     response.Close();
     return authUrl;
 }
Example #5
-1
 public object getApiInfo()
 {
     OAuthRequest client = new OAuthRequest()
     {
         Method = "GET",
         Type = OAuthRequestType.ProtectedResource,
         SignatureMethod = OAuthSignatureMethod.HmacSha1,
         ConsumerKey = this.consumerKey,
         ConsumerSecret = this.consumerSecret,
         RequestUrl = "https://api.shapeways.com/api/v1",
         Version = "1.0a",
         Realm = "shapeways.com",
         TokenSecret = this.OAuthSecret,
         Token = this.OAuthToken,
     };
     string auth = client.GetAuthorizationQuery();
     string requestUrl = client.RequestUrl + "?" + auth;
     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
     string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
     return JsonConvert.DeserializeObject(content);
 }