Exemple #1
0
 // Constructor for standard OAuth
 public OAuthAuthorizer(OAuthConfig config)
 {
     this.config = config;
 }
Exemple #2
0
        public static void AuthorizeRequest(OAuthConfig config, WebClient wc, string oauthToken, string oauthTokenSecret, string method, Uri uri, string data)
        {
            var headers = new Dictionary<string, string>() {
                { "oauth_consumer_key", config.ConsumerKey },
                { "oauth_nonce", MakeNonce () },
                { "oauth_signature_method", "HMAC-SHA1" },
                { "oauth_timestamp", MakeTimestamp () },
                { "oauth_token", oauthToken },
                { "oauth_version", "1.0" }};
            var signatureHeaders = new Dictionary<string,string> (headers);

            // Add the data and URL query string to the copy of the headers for computing the signature
            if (data != null && data != ""){
                var parsed = Http.ParseQueryString (data);
                foreach (string k in parsed.Keys){
                    signatureHeaders.Add (k, OAuth.PercentEncode (parsed [k]));

                    if (k == "oauth_verifier") {
                        headers.Add(k, parsed[k]);
                    }
                }
            }

            var nvc = Http.ParseQueryString (uri.Query);
            foreach (string key in nvc.Keys){
                if (key != null)
                    signatureHeaders.Add (key, OAuth.PercentEncode (nvc [key]));
            }

            string signature = MakeSignature (method, uri.GetLeftPart (UriPartial.Path), signatureHeaders);
            string compositeSigningKey = MakeSigningKey (config.ConsumerSecret, oauthTokenSecret);
            string oauth_signature = MakeOAuthSignature (compositeSigningKey, signature);

            headers.Add ("oauth_signature", OAuth.PercentEncode (oauth_signature));

            wc.Headers [HttpRequestHeader.Authorization] = HeadersToOAuth (headers);
        }