Beispiel #1
0
        static bool AccessToken(string verifier)
        {
            try
            {
                var obj  = new { oauth_verifier = verifier };
                var buff = OAuth.ToString(obj);

                using (var wc = new WebClient())
                {
                    wc.Headers.Add("Authorization", OAuth.GenerateAuthorization(ct, cs, ut, us, "POST", "https://api.twitter.com/oauth/access_token", obj));
                    wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

                    var r = wc.UploadString("https://api.twitter.com/oauth/access_token", buff);

                    ut = Regex.Match(r, @"oauth_token=([^&]+)").Groups[1].Value;
                    us = Regex.Match(r, @"oauth_token_secret=([^&]+)").Groups[1].Value;
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        public static async Task OnRequest(object sender, SessionEventArgs e)
        {
            var requestHeaders = e.WebSession.Request.Headers;

            //if (requestHeaders.HeaderExists("Authorization") && requestHeaders.Headers["Authorization"].Value.Contains("SyFYmZ2qa9eI9p7sheZFlw"))
            var headerExists = requestHeaders.HeaderExists("Authorization");

            if (headerExists || e.WebSession.Request.Url.Contains("oauth_signature"))
            {
                string bodyString = null;

                if (e.WebSession.Request.HasBody)
                {
                    bodyString = await e.GetRequestBodyAsString();
                }

                var newAuthorization =
                    OAuth.GenerateAuthorization(
                        ct,
                        cs,
                        ut,
                        us,
                        e.WebSession.Request.Method,
                        e.WebSession.Request.Url,
                        bodyString);

                if (headerExists)
                {
                    e.WebSession.Request.Headers.Headers["Authorization"].Value = newAuthorization;
                }
                else
                {
                    e.WebSession.Request.Headers.AddHeader("Authorization", newAuthorization);
                }

                if (e.WebSession.Request.HasBody)
                {
                    await e.SetRequestBodyString(bodyString);

                    var bodyBytes = await e.GetRequestBody();

                    await e.SetRequestBody(bodyBytes);
                }
            }
            else if (e.WebSession.Request.HasBody)
            {
                var bodyString = await e.GetRequestBodyAsString();

                await e.SetRequestBodyString(bodyString);

                var bodyBytes = await e.GetRequestBody();

                await e.SetRequestBody(bodyBytes);
            }
        }
Beispiel #3
0
        static bool RequestToken()
        {
            try
            {
                using (var wc = new WebClient())
                {
                    wc.Headers.Add("Authorization", OAuth.GenerateAuthorization(ct, cs, null, null, "POST", "https://api.twitter.com/oauth/request_token", null));

                    var r = wc.UploadString("https://api.twitter.com/oauth/request_token", "");

                    ut = Regex.Match(r, @"oauth_token=([^&]+)").Groups[1].Value;
                    us = Regex.Match(r, @"oauth_token_secret=([^&]+)").Groups[1].Value;
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }