Пример #1
0
        private string GenerateSignature(HttpWebRequest request, FormParameters formParameters)
        {
            FormParameters parameters = FormParameters.OAuthDecode(request.RequestUri.Query);

            foreach (var item in _protocolParameters)
            {
                parameters.Add(item);
            }
            if (request.ContentType == "application/x-www-form-urlencoded")
            {
                foreach (var item in formParameters)
                {
                    parameters.Add(item);
                }
            }
            parameters.Sort();

            string signature = GenerateBaseSignature(request.Method, request.RequestUri, parameters);
            string secret    = EncodeSecret();

            Trace.WriteLine("Secret: " + secret);
            Trace.WriteLine("Signature: " + signature);

            return(Sign(secret, signature));
        }
Пример #2
0
        private void SetTempToken()
        {
            FormParameters form = new FormParameters();

            if (TempTokenRequesting != null)
            {
                TempTokenRequesting(this, new OAuthRequestTokenEventArgs(form));
            }
            //_protocolParameters.Set("oauth_callback", CallbackUrl);
            form.Add("oauth_callback", CallbackUrl);

            // TODO: check TempTokenMethod

            HttpWebResponse response = AuthorizedPOST(TemporaryCredentialsUri, form);

            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                string         text  = sr.ReadToEnd();
                FormParameters reply = FormParameters.OAuthDecode(text);
                AuthorizedToken       = reply["oauth_token"];
                AuthorizedTokenSecret = reply["oauth_token_secret"];

                // TODO pass additional parameters to impl
            }
        }
Пример #3
0
        public static FormParameters FormDecode(string message)
        {
            FormParameters form = new FormParameters();

            if (String.IsNullOrWhiteSpace(message))
            {
                return(form);
            }
            foreach (var pair in message.Split('&'))
            {
                string[] parts = pair.Split('=');
                string   key   = HttpUtility.UrlDecode(parts[0], Encoding.UTF8);
                string   value = parts.Length > 1
                    ? HttpUtility.UrlDecode(parts[1], Encoding.UTF8)
                    : String.Empty;
                form.Add(key, value);
            }
            return(form);
        }
Пример #4
0
        public static FormParameters OAuthDecode(string message)
        {
            FormParameters form = new FormParameters();

            message = message.TrimStart('?');
            if (String.IsNullOrWhiteSpace(message))
            {
                return(form);
            }
            foreach (var pair in message.Split('&'))
            {
                string[] parts = pair.Split('=');
                string   key   = OAuthClientBase.Decode(parts[0]);
                string   value = parts.Length > 1
                    ? OAuthClientBase.Decode(parts[1])
                    : String.Empty;
                form.Add(key, value);
            }
            return(form);
        }