GenerateAuthzHeader() public method

Generate a string to be used in an Authorization header in an HTTP request.

This method assembles the available oauth_ parameters that have been set in the Dictionary in this instance, produces the signature base (As described by the OAuth spec, RFC 5849), signs it, then re-formats the oauth_ parameters into the appropriate form, including the oauth_signature value, and returns the result.

public GenerateAuthzHeader ( string uri, string method ) : string
uri string
method string
return string
Ejemplo n.º 1
0
        private void SetHeader(string uri, string method = "GET")
        {
            string header = oAuth.GenerateAuthzHeader(uri, method);

            client.DefaultRequestHeaders.Remove("Authorization");
            client.DefaultRequestHeaders.Add("Authorization", header);
        }
Ejemplo n.º 2
0
 public string RegenerateHeaders(string token, string token_secret)
 {
     OAuth = new OAuth.Manager(_ConsumerKey,_ConsumerSecret,token,token_secret);
     var search = "http://api.discogs.com/oauth/identity";
     var authHeader = OAuth.GenerateAuthzHeader(search, "GET");
     return authHeader;
 }
Ejemplo n.º 3
0
        public string AuthorizeApp(string pin)
        {
            OAuthResponse accessToken = OAuth.AcquireAccessToken("http://api.discogs.com/oauth/access_token", "POST", pin, _UserAgent);
            var           search      = "http://api.discogs.com/oauth/identity";
            var           authHeader  = OAuth.GenerateAuthzHeader(search, "GET");

            return(authHeader);
        }
Ejemplo n.º 4
0
        public string RegenerateHeaders(string token, string token_secret)
        {
            OAuth = new OAuth.Manager(_ConsumerKey, _ConsumerSecret, token, token_secret);
            var search     = "http://api.discogs.com/oauth/identity";
            var authHeader = OAuth.GenerateAuthzHeader(search, "GET");

            return(authHeader);
        }
Ejemplo n.º 5
0
        public bool Tweet(string imageFile, string message, oAuthTwitter oAuth)
        {
            bool bupdated = false;

            try
            {
                //HttpContext.Current.Response.Write("<script>alert(\""+imageFile+"\")</script>");

                oauth["consumer_key"] = oAuth.ConsumerKey;

                oauth["consumer_secret"] = oAuth.ConsumerKeySecret;
                oauth["token"]           = oAuth.AccessToken;
                oauth["token_secret"]    = oAuth.AccessTokenSecret;

                var url = GetTwitterUpdateUrl(imageFile, message);
                if (url == twitterUrl1)
                {
                    strdic.Add("status", message);
                }
                var authzHeader = oauth.GenerateAuthzHeader(url, "POST");
                var request     = (HttpWebRequest)WebRequest.Create(url);

                request.Method                    = "POST";
                request.PreAuthenticate           = true;
                request.AllowWriteStreamBuffering = true;
                request.Headers.Add("Authorization", authzHeader);

                request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                if (imageFile != null)
                {
                    string boundary = "======" +
                                      Guid.NewGuid().ToString().Substring(18).Replace("-", "") +
                                      "======";

                    var separator = "--" + boundary;
                    var footer    = "\r\n" + separator + "--\r\n";

                    string shortFileName   = Path.GetFileName(imageFile);
                    string fileContentType = GetMimeType(shortFileName);
                    string fileHeader      = string.Format("Content-Disposition: file; " +
                                                           "name=\"media\"; filename=\"{0}\"",
                                                           shortFileName);
                    var encoding = System.Text.Encoding.GetEncoding("iso-8859-1");

                    var contents = new System.Text.StringBuilder();
                    contents.AppendLine(separator);
                    contents.AppendLine("Content-Disposition: form-data; name=\"status\"");
                    contents.AppendLine();
                    contents.AppendLine(message);
                    contents.AppendLine(separator);
                    contents.AppendLine(fileHeader);
                    contents.AppendLine(string.Format("Content-Type: {0}", fileContentType));
                    contents.AppendLine();

                    request.ServicePoint.Expect100Continue = false;
                    request.ContentType = "multipart/form-data; boundary=" + boundary;
                    // actually send the request
                    using (var s = request.GetRequestStream())
                    {
                        byte[] bytes = encoding.GetBytes(contents.ToString());
                        s.Write(bytes, 0, bytes.Length);
                        bytes = File.ReadAllBytes(imageFile);
                        s.Write(bytes, 0, bytes.Length);
                        bytes = encoding.GetBytes(footer);
                        s.Write(bytes, 0, bytes.Length);
                    }
                }


                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    //   HttpContext.Current.Response.Write("<script>alert(\"" + response.StatusCode + "\")</script>");

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        bupdated = true;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                logger.Error(ex.Message);
                //using (StreamWriter _testData = new StreamWriter(HttpContext.Current.Server.MapPath("~/log.txt"), true))
                //{
                //    _testData.WriteLine("Error on PhotoUpload : " + ex.Message); // Write the file.

                //}
            }


            return(bupdated);
        }