예제 #1
0
        private void AddAuthParameters(
            ICollection <WebParameter> parameters,
            string timestamp,
            string nonce)
        {
            WebParameterCollection parameterCollection = new WebParameterCollection()
            {
                new WebParameter("oauth_consumer_key", this.ConsumerKey),
                new WebParameter("oauth_nonce", nonce),
                new WebParameter("oauth_signature_method", OAuthRequest.ToRequestValue(this.SignatureMethod)),
                new WebParameter("oauth_timestamp", timestamp),
                new WebParameter("oauth_version", this.Version ?? "1.0")
            };

            if (!OAuthRequest.IsNullOrBlank(this.Token))
            {
                parameterCollection.Add(new WebParameter("oauth_token", this.Token));
            }
            if (!OAuthRequest.IsNullOrBlank(this.CallbackUrl))
            {
                parameterCollection.Add(new WebParameter("oauth_callback", this.CallbackUrl));
            }
            if (!OAuthRequest.IsNullOrBlank(this.Verifier))
            {
                parameterCollection.Add(new WebParameter("oauth_verifier", this.Verifier));
            }
            if (!OAuthRequest.IsNullOrBlank(this.SessionHandle))
            {
                parameterCollection.Add(new WebParameter("oauth_session_handle", this.SessionHandle));
            }
            foreach (WebParameter webParameter in parameterCollection)
            {
                parameters.Add(webParameter);
            }
        }
예제 #2
0
        private string WriteAuthorizationHeader(WebParameterCollection parameters)
        {
            StringBuilder stringBuilder = new StringBuilder("OAuth ");

            if (!OAuthRequest.IsNullOrBlank(this.Realm))
            {
                stringBuilder.AppendFormat("realm=\"{0}\",", (object)OAuthTools.UrlEncodeRelaxed(this.Realm));
            }
            parameters.Sort((Comparison <WebParameter>)((l, r) => l.Name.CompareTo(r.Name)));
            int num = 0;

            foreach (WebParameter webParameter in parameters.Where <WebParameter>((Func <WebParameter, bool>)(parameter =>
            {
                if (!OAuthRequest.IsNullOrBlank(parameter.Name) && !OAuthRequest.IsNullOrBlank(parameter.Value))
                {
                    return(parameter.Name.StartsWith("oauth_"));
                }
                return(false);
            })))
            {
                ++num;
                string format = num < parameters.Count ? "{0}=\"{1}\"," : "{0}=\"{1}\"";
                stringBuilder.AppendFormat(format, (object)webParameter.Name, (object)webParameter.Value);
            }
            return(stringBuilder.ToString());
        }
예제 #3
0
 private void ValidateProtectedResourceState()
 {
     if (OAuthRequest.IsNullOrBlank(this.Method))
     {
         throw new ArgumentException("You must specify an HTTP method");
     }
     if (OAuthRequest.IsNullOrBlank(this.ConsumerKey))
     {
         throw new ArgumentException("You must specify a consumer key");
     }
     if (OAuthRequest.IsNullOrBlank(this.ConsumerSecret))
     {
         throw new ArgumentException("You must specify a consumer secret");
     }
 }
예제 #4
0
 private void ValidateRequestState()
 {
     if (OAuthRequest.IsNullOrBlank(this.Method))
     {
         throw new ArgumentException("You must specify an HTTP method");
     }
     if (OAuthRequest.IsNullOrBlank(this.RequestUrl))
     {
         throw new ArgumentException("You must specify a request token URL");
     }
     if (OAuthRequest.IsNullOrBlank(this.ConsumerKey))
     {
         throw new ArgumentException("You must specify a consumer key");
     }
     if (OAuthRequest.IsNullOrBlank(this.ConsumerSecret))
     {
         throw new ArgumentException("You must specify a consumer secret");
     }
 }
예제 #5
0
        private string WriteAuthorizationHeader(WebParameterCollection parameters)
        {
            StringBuilder stringBuilder = new StringBuilder("OAuth ");

            if (!OAuthRequest.IsNullOrBlank(this.Realm))
            {
                stringBuilder.AppendFormat("realm=\"{0}\",", OAuthTools.UrlEncodeRelaxed(this.Realm));
            }
            parameters.Sort((WebParameter l, WebParameter r) => l.Name.CompareTo(r.Name));
            int num = 0;

            foreach (WebParameter webParameter in parameters.Where((WebParameter parameter) => !OAuthRequest.IsNullOrBlank(parameter.Name) && !OAuthRequest.IsNullOrBlank(parameter.Value) && (parameter.Name.StartsWith("oauth_") || parameter.Name.StartsWith("x_auth_"))))
            {
                num++;
                string format = (num >= parameters.Count) ? "{0}=\"{1}\"" : "{0}=\"{1}\",";
                stringBuilder.AppendFormat(format, webParameter.Name, webParameter.Value);
            }
            return(stringBuilder.ToString());
        }
예제 #6
0
        private static string WriteAuthorizationQuery(WebParameterCollection parameters)
        {
            StringBuilder stringBuilder = new StringBuilder();

            parameters.Sort((Comparison <WebParameter>)((l, r) => l.Name.CompareTo(r.Name)));
            int num = 0;

            foreach (WebParameter webParameter in parameters.Where <WebParameter>((Func <WebParameter, bool>)(parameter =>
            {
                if (!OAuthRequest.IsNullOrBlank(parameter.Name) && !OAuthRequest.IsNullOrBlank(parameter.Value))
                {
                    return(parameter.Name.StartsWith("oauth_"));
                }
                return(false);
            })))
            {
                ++num;
                string format = num < parameters.Count ? "{0}={1}&" : "{0}={1}";
                stringBuilder.AppendFormat(format, (object)webParameter.Name, (object)webParameter.Value);
            }
            return(stringBuilder.ToString());
        }
예제 #7
0
 private void ValidateClientAuthAccessRequestState()
 {
     if (OAuthRequest.IsNullOrBlank(this.Method))
     {
         throw new ArgumentException("You must specify an HTTP method");
     }
     if (OAuthRequest.IsNullOrBlank(this.RequestUrl))
     {
         throw new ArgumentException("You must specify an access token URL");
     }
     if (OAuthRequest.IsNullOrBlank(this.ConsumerKey))
     {
         throw new ArgumentException("You must specify a consumer key");
     }
     if (OAuthRequest.IsNullOrBlank(this.ConsumerSecret))
     {
         throw new ArgumentException("You must specify a consumer secret");
     }
     if (OAuthRequest.IsNullOrBlank(this.ClientUsername) || OAuthRequest.IsNullOrBlank(this.ClientPassword))
     {
         throw new ArgumentException("You must specify user credentials");
     }
 }
예제 #8
0
        private static string WriteAuthorizationQuery(WebParameterCollection parameters)
        {
            StringBuilder stringBuilder = new StringBuilder();

            parameters.Sort((WebParameter l, WebParameter r) => l.Name.CompareTo(r.Name));
            int num = 0;

            foreach (WebParameter webParameter in parameters.Where((WebParameter parameter) => !OAuthRequest.IsNullOrBlank(parameter.Name) && !OAuthRequest.IsNullOrBlank(parameter.Value) && (parameter.Name.StartsWith("oauth_") || parameter.Name.StartsWith("x_auth_"))))
            {
                num++;
                string format = (num >= parameters.Count) ? "{0}={1}" : "{0}={1}&";
                stringBuilder.AppendFormat(format, webParameter.Name, webParameter.Value);
            }
            return(stringBuilder.ToString());
        }