예제 #1
0
        public MainPage()
        {
            InitializeComponent();

            oauth = new OAuth.OAuthBase();
            client = new WebClient();

            // stisk <Enter> v editacnim poli
            tbHledat.KeyUp +=
                (sender, e) =>
                {
                    if (e.Key == Key.Enter)
                        Hledani();
                };

            // stisk tlacitka Hledej
            btnHledej.Click +=
                (sender, e) =>
                    Hledani();

            // callback pokud dojde odpoved ze serveru
            client.DownloadStringCompleted +=
                (sender, e) =>
                {
                    if (e.Error == null)
                        XmlVysledky(e.Result);
                };

            // prvni hledani
            Hledani();
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            OAuth.OAuthBase.SignatureTypes signatureType = OAuth.OAuthBase.SignatureTypes.HMACSHA1;
            string normalizedUrl;
            string normalizedRequestParameters;
            OAuth.OAuthBase myOAuth = new OAuth.OAuthBase();

            try
            {
                Uri uri = new Uri(txtURI.Text);
                string consumerKey = txtConsKey.Text;
                string consumerSecret = txtConsSecret.Text;
                string token = txtToken.Text;
                string tokenSecret = txtTokenSecret.Text;
                string httpMethod = drpHTTPMethod.SelectedItem.ToString();
                string timeStamp = txtTimestamp.Text;
                string nonce = txtNonce.Text;

                if (string.IsNullOrEmpty(timeStamp))
                {
                    timeStamp = myOAuth.GenerateTimeStamp();
                    txtTimestamp.Text = timeStamp;
                }

                if (string.IsNullOrEmpty(nonce))
                {
                    nonce = myOAuth.GenerateNonce();
                    txtNonce.Text = nonce;
                }

                switch (drpSigMethod.SelectedIndex)
                {
                    case 0:
                        signatureType = OAuth.OAuthBase.SignatureTypes.HMACSHA1;
                        break;
                    case 1:
                        signatureType = OAuth.OAuthBase.SignatureTypes.PLAINTEXT;
                        break;
                    case 2:
                        signatureType = OAuth.OAuthBase.SignatureTypes.RSASHA1;
                        break;
                }

                myOAuth.includeVersion = chkVersion.Checked;

                string signature = myOAuth.GenerateSignature(uri, consumerKey, consumerSecret,
                    token, tokenSecret, httpMethod, timeStamp, nonce, signatureType,
                    out normalizedUrl, out normalizedRequestParameters);

                txtRawSig.Text = signature;
                txtEncodedSig.Text = myOAuth.UrlEncode(signature);

                txtGenURL.Text = normalizedUrl + "?" + normalizedRequestParameters + "&oauth_signature=" + txtEncodedSig.Text;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// Construct a signed USOS API URL which points to a given method with
        /// given arguments.
        /// </summary>
        /// <param name="method">USOS API method to call.</param>
        /// <param name="args">A dictionary of method argument values for this call.</param>
        /// <param name="consumer_key">Your Consumer Key (if you want to sign this request).</param>
        /// <param name="consumer_secret">Your Consumer Secret (if you want to sign this request).</param>
        /// <param name="token">Your Token (if you want to sign this request).</param>
        /// <param name="token_secret">Your Token Secret (if you want to sign this request).</param>
        /// <returns></returns>
        public string GetURL(ApiMethod method, Dictionary <string, string> args = null,
                             string consumer_key = "", string consumer_secret = "", string token = "",
                             string token_secret = "", bool use_ssl           = false)
        {
            var oauth = new OAuth.OAuthBase();

            if (args == null)
            {
                args = new Dictionary <string, string>();
            }

            var argPairsEncoded = new List <string>();

            foreach (var pair in args)
            {
                argPairsEncoded.Add(oauth.UrlEncode(pair.Key) + "=" + oauth.UrlEncode(pair.Value));
            }
            string url = this.currentInstallation.base_url + method.name;

            if (use_ssl)
            {
                url = url.Replace("http://", "https://");
            }
            if (argPairsEncoded.Count > 0)
            {
                url += "?" + string.Join("&", argPairsEncoded);
            }

            // We have our base version of the URL, with no OAuth arguments. Now we will
            // add standard OAuth stuff and sign it given Consumer Secret (and optionally
            // also with Token Secret).

            if (consumer_key == "")
            {
                return(url);
            }

            string timestamp = oauth.GenerateTimeStamp();
            string nonce     = oauth.GenerateNonce();
            string normalized_url;
            string normalized_params;
            string signature = oauth.GenerateSignature(new System.Uri(url), consumer_key,
                                                       consumer_secret, token, token_secret, "GET", timestamp, nonce, out normalized_url,
                                                       out normalized_params);

            url = this.currentInstallation.base_url;
            if (use_ssl)
            {
                url = url.Replace("http://", "https://");
            }
            url += method.name + "?" + normalized_params + "&oauth_signature=" + HttpUtility.UrlEncode(signature);

            return(url);
        }
예제 #4
0
        public string getSignedUrl(string url)
        {
            string normalizedUrl       = string.Empty;
            string normalizedReqParams = string.Empty;

            OAuth.OAuthBase oauth     = new OAuth.OAuthBase();
            string          signature = oauth.GenerateSignature(new Uri(url), API_KEY, SHARED_SECRET, null, null, "GET", oauth.GenerateTimeStamp(), oauth.GenerateNonce(), out normalizedUrl, out normalizedReqParams);

            signature           = HttpUtility.UrlEncode(signature);
            normalizedReqParams = string.Join("&", new string[] { normalizedReqParams, string.Format("oauth_signature={0}", signature) });
            string finalUrl = string.Join("?", new string[] { normalizedUrl, normalizedReqParams });

            return(finalUrl);
        }
예제 #5
0
        public string SearchTitles(string titleName, string maxResults)
        {
            OAuth.OAuthBase oauth = new OAuth.OAuthBase();

            // add inputs
            Uri requestUrl = new Uri("http://api-public.netflix.com/catalog/titles/");

            oauth.AddQueryParameter("term", titleName);
            oauth.AddQueryParameter("max_results", maxResults);

            // prepare outputs
            string normalizedUrl;
            string normalizedRequestParameters;

            // generate request signature
            string sig = oauth.GenerateSignature(requestUrl,
                                                 SettingsProvider.ConsumerKey,
                                                 SettingsProvider.SharedSecret,
                                                 null,
                                                 null,          // token , tokenSecret (not needed)
                                                 "GET",
                                                 oauth.GenerateTimeStamp(),
                                                 oauth.GenerateNonce(),
                                                 out normalizedUrl,
                                                 out normalizedRequestParameters);
            // construct request
            var request = requestUrl + "?" +
                          normalizedRequestParameters +
                          "&oauth_signature=" + oauth.UrlEncode(sig);
            // make request
            string results = "";

            WebRequest req = WebRequest.Create(request);

            using (WebResponse rsp = req.GetResponse())
            {
                using (StreamReader sr = new StreamReader(rsp.GetResponseStream()))
                {
                    results = sr.ReadToEnd();
                }
            }

            return(results);
        }
예제 #6
0
        public string SearchTitles(string titleName, string maxResults)
        {
            OAuth.OAuthBase oauth = new OAuth.OAuthBase();

            // add inputs
            Uri requestUrl = new Uri("http://api-public.netflix.com/catalog/titles/");
            oauth.AddQueryParameter("term", titleName);
            oauth.AddQueryParameter("max_results", maxResults);

            // prepare outputs
            string normalizedUrl;
            string normalizedRequestParameters;

            // generate request signature
            string sig = oauth.GenerateSignature(requestUrl,
                                                 SettingsProvider.ConsumerKey,
                                                 SettingsProvider.SharedSecret,
                                                 null,
                                                 null,		// token , tokenSecret (not needed)
                                                 "GET",
                                                 oauth.GenerateTimeStamp(),
                                                 oauth.GenerateNonce(),
                                                 out normalizedUrl,
                                                 out normalizedRequestParameters);
            // construct request
            var request = requestUrl + "?" +
                            normalizedRequestParameters +
                            "&oauth_signature=" + oauth.UrlEncode(sig);
            // make request
            string results = "";

            WebRequest req = WebRequest.Create(request);
            using (WebResponse rsp = req.GetResponse())
            {
                using (StreamReader sr = new StreamReader(rsp.GetResponseStream()))
                {
                    results = sr.ReadToEnd();
                }
            }

            return results;
        }
예제 #7
0
        /// <summary>
        /// Construct a signed OKAPI URL which points to a given method with
        /// given arguments.
        /// </summary>
        /// <param name="method">OKAPI method to call.</param>
        /// <param name="args">A dictionary of method argument values for this call.</param>
        /// <param name="consumer_key">Your Consumer Key (if you want to sign this request).</param>
        /// <param name="consumer_secret">Your Consumer Secret (if you want to sign this request).</param>
        /// <param name="token">Your Token (if you want to sign this request).</param>
        /// <param name="token_secret">Your Token Secret (if you want to sign this request).</param>
        /// <returns></returns>
        public string GetURL(ApiMethod method, Dictionary<string, string> args = null,
            string consumer_key = "", string consumer_secret = "", string token = "",
            string token_secret = "", bool use_ssl = false)
        {
            var oauth = new OAuth.OAuthBase();
            if (args == null)
                args = new Dictionary<string, string>();

            var argPairsEncoded = new List<string>();
            foreach (var pair in args)
            {
                argPairsEncoded.Add(oauth.UrlEncode(pair.Key) + "=" + oauth.UrlEncode(pair.Value));
            }
            string url = this.currentInstallation.base_url + method.name;
            if (use_ssl)
                url = url.Replace("http://", "https://");
            if (argPairsEncoded.Count > 0)
                url += "?" + string.Join("&", argPairsEncoded);

            // We have our base version of the URL, with no OAuth arguments. Now we will
            // add standard OAuth stuff and sign it given Consumer Secret (and optionally
            // also with Token Secret).

            if (consumer_key == "")
                return url;

            string timestamp = oauth.GenerateTimeStamp();
            string nonce = oauth.GenerateNonce();
            string normalized_url;
            string normalized_params;
            string signature = oauth.GenerateSignature(new System.Uri(url), consumer_key,
                consumer_secret, token, token_secret, "GET", timestamp, nonce, out normalized_url,
                out normalized_params);
            url = this.currentInstallation.base_url;
            if (use_ssl)
                url = url.Replace("http://", "https://");
            url += method.name + "?" + normalized_params + "&oauth_signature=" + HttpUtility.UrlEncode(signature);

            return url;
        }
예제 #8
0
        public string getSignedUrl(string url)
        {
            string normalizedUrl = string.Empty;
            string normalizedReqParams = string.Empty;
            OAuth.OAuthBase oauth = new OAuth.OAuthBase();
            string signature = oauth.GenerateSignature(new Uri(url), API_KEY, SHARED_SECRET, null, null, "GET", oauth.GenerateTimeStamp(), oauth.GenerateNonce(), out normalizedUrl, out normalizedReqParams);

            signature = HttpUtility.UrlEncode(signature);
            normalizedReqParams = string.Join("&", new string[] { normalizedReqParams, string.Format("oauth_signature={0}", signature) });
            string finalUrl = string.Join("?", new string[] { normalizedUrl, normalizedReqParams });

            return finalUrl;
        }
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            OAuth.OAuthBase.SignatureTypes signatureType = OAuth.OAuthBase.SignatureTypes.HMACSHA1;
            string normalizedUrl;
            string normalizedRequestParameters;

            OAuth.OAuthBase myOAuth = new OAuth.OAuthBase();

            try
            {
                Uri    uri            = new Uri(txtURI.Text);
                string consumerKey    = txtConsKey.Text;
                string consumerSecret = txtConsSecret.Text;
                string token          = txtToken.Text;
                string tokenSecret    = txtTokenSecret.Text;
                string httpMethod     = drpHTTPMethod.SelectedItem.ToString();
                string timeStamp      = txtTimestamp.Text;
                string nonce          = txtNonce.Text;

                if (string.IsNullOrEmpty(timeStamp))
                {
                    timeStamp         = myOAuth.GenerateTimeStamp();
                    txtTimestamp.Text = timeStamp;
                }

                if (string.IsNullOrEmpty(nonce))
                {
                    nonce         = myOAuth.GenerateNonce();
                    txtNonce.Text = nonce;
                }

                switch (drpSigMethod.SelectedIndex)
                {
                case 0:
                    signatureType = OAuth.OAuthBase.SignatureTypes.HMACSHA1;
                    break;

                case 1:
                    signatureType = OAuth.OAuthBase.SignatureTypes.PLAINTEXT;
                    break;

                case 2:
                    signatureType = OAuth.OAuthBase.SignatureTypes.RSASHA1;
                    break;
                }

                myOAuth.includeVersion = chkVersion.Checked;

                string signature = myOAuth.GenerateSignature(uri, consumerKey, consumerSecret,
                                                             token, tokenSecret, httpMethod, timeStamp, nonce, signatureType,
                                                             out normalizedUrl, out normalizedRequestParameters);

                txtRawSig.Text     = signature;
                txtEncodedSig.Text = myOAuth.UrlEncode(signature);

                txtGenURL.Text = normalizedUrl + "?" + normalizedRequestParameters + "&oauth_signature=" + txtEncodedSig.Text;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }