コード例 #1
0
        /// <summary>
        /// Takes an existing httpwebrequest and modifies it's headers according to
        /// the authentication system used.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public override void ApplyAuthenticationToRequest(HttpWebRequest request)
        {
            base.ApplyAuthenticationToRequest(request);

            string oauthHeader = OAuthUtil.GenerateHeader(request.RequestUri,
                                                          this.ConsumerKey,
                                                          this.ConsumerSecret,
                                                          this.Token,
                                                          this.TokenSecret,
                                                          request.Method);

            request.Headers.Add(oauthHeader);
        }
コード例 #2
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>sets up the correct credentials for this call</summary>
        //////////////////////////////////////////////////////////////////////
        protected override void EnsureCredentials()
        {
            HttpWebRequest http = this.Request as HttpWebRequest;

            if (string.IsNullOrEmpty(this.factory.ConsumerKey) || string.IsNullOrEmpty(this.factory.ConsumerSecret))
            {
                throw new GDataRequestException("ConsumerKey and ConsumerSecret must be provided to use GOAuthRequestFactory");
            }

            string oauthHeader = OAuthUtil.GenerateHeader(http.RequestUri,
                                                          this.factory.ConsumerKey,
                                                          this.factory.ConsumerSecret,
                                                          this.factory.Token,
                                                          this.factory.TokenSecret,
                                                          http.Method);

            this.Request.Headers.Remove("Authorization"); // needed?
            this.Request.Headers.Add(oauthHeader);
        }
コード例 #3
0
        public static string GenerateHeader(Uri uri, String consumerKey, String consumerSecret, String token, String tokenSecret, String httpMethod)
        {
            OAuthUtil oauthUtil = new OAuthUtil();
            string    timeStamp = oauthUtil.GenerateTimeStamp();
            string    nonce     = oauthUtil.GenerateNonce();

            string signature = oauthUtil.GenerateSignature(uri, consumerKey, consumerSecret, token, tokenSecret,
                                                           httpMethod.ToUpper(), timeStamp, nonce);

            StringBuilder sb = new StringBuilder();

            sb.Append("Authorization: OAuth oauth_version=\"1.0\",");
            sb.AppendFormat("oauth_nonce=\"{0}\",", EncodingPerRFC3986(nonce));
            sb.AppendFormat("oauth_timestamp=\"{0}\",", EncodingPerRFC3986(timeStamp));
            sb.AppendFormat("oauth_consumer_key=\"{0}\",", EncodingPerRFC3986(consumerKey));
            if (!String.IsNullOrEmpty(token))
            {
                sb.AppendFormat("oauth_token=\"{0}\",", EncodingPerRFC3986(token));
            }
            sb.Append("oauth_signature_method=\"HMAC-SHA1\",");
            sb.AppendFormat("oauth_signature=\"{0}\"", EncodingPerRFC3986(signature));

            return(sb.ToString());
        }