Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <returns></returns>
        public AccessTokenInfo GetAccessToken(String requestToken, String requestTokenSecret)
        {
            String nonce     = OAuthClient.GenerateNonce();
            String timestamp = OAuthClient.GenerateTimeStamp();
            String url       = this.AccessTokenUrl;

            SignatureInfo si = OAuthClient.GenerateSignature(new Uri(url), this.ConsumerKey, this.ConsumerSecret
                                                             , requestToken, requestTokenSecret, "POST", timestamp, nonce, OAuthClient.SignatureTypes.HMACSHA1);
            HttpClient cl = new HttpClient(String.Format("{0}?{1}&oauth_signature={2}"
                                                         , url, si.NormalizedRequestParameters, si.Signature));
            String result = cl.GetBodyText();

            return(AccessTokenInfo.Create(result, "oauth_token", "oauth_token_secret"));
        }
Пример #2
0
        private HttpClient CreateHttpClientRequestHeaderMode(HttpMethodName methodName, String url, String token, String tokenSecret, IDictionary <String, String> queryString)
        {
            String timeStamp = OAuthClient.GenerateTimeStamp();
            String nonce     = OAuthClient.GenerateNonce();
            Dictionary <String, String> pp = OAuthClient.GenerateParameters(ConsumerKey, token, timeStamp, nonce);
            Uri           u  = new Uri(HttpClient.CreateQueryString(url, queryString, OAuthClient.UrlEncode));
            SignatureInfo si = GenerateSignature(u, this.ConsumerKey, this.ConsumerSecret, token, tokenSecret
                                                 , methodName.ToString().ToUpper(), timeStamp, nonce);

            pp.Add("oauth_signature", OAuthClient.UrlEncode(si.Signature));
            //NOTE:NET2.0
            HttpClient cl = new HttpClient(HttpClient.CreateQueryString(url, queryString, HttpClient.UrlEncode));

            cl.MethodName = methodName;
            cl.Headers[HttpRequestHeader.Authorization] = this.CreateOAuthHeader(pp);
            return(cl);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public AuthorizeInfo GetAuthorizeInfo()
        {
            String nonce     = OAuthClient.GenerateNonce();
            String timestamp = OAuthClient.GenerateTimeStamp();
            String url       = this.RequestTokenUrl;

            SignatureInfo si = OAuthClient.GenerateSignature(new Uri(url), this.ConsumerKey, this.ConsumerSecret
                                                             , "", "", "GET", timestamp, nonce, OAuthClient.SignatureTypes.HMACSHA1);
            HttpClient cl     = new HttpClient(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature));
            String     result = cl.GetBodyText();
            //正規表現でoauth_token,oauth_token_secret取得
            AuthorizeInfo ai = new AuthorizeInfo();

            ai.AuthorizeUrl       = String.Format("{0}?{1}", this.AuthorizeUrl, result);
            ai.RequestToken       = this.GetMatchValue(RegexList.OAuthToken, result);
            ai.RequestTokenSecret = this.GetMatchValue(RegexList.OAuthTokenSecret, result);
            return(ai);
        }
Пример #4
0
        private HttpClient CreateHttpClientQueryStringMode(HttpMethodName methodName, String url, String token, String tokenSecret, IEnumerable <KeyValuePair <string, string> > queryString)
        {
            String timeStamp = OAuthClient.GenerateTimeStamp();
            String nonce     = OAuthClient.GenerateNonce();
            Dictionary <String, String> pp = OAuthClient.GenerateParameters(ConsumerKey, token, timeStamp, nonce);

            foreach (KeyValuePair <string, string> p in queryString)
            {
                pp.Add(p.Key, p.Value);
            }
            //NOTE:NET2.0
            Uri           u  = new Uri(HttpClient.CreateQueryString(url, pp, OAuthClient.UrlEncode));
            SignatureInfo si = GenerateSignature(u, this.ConsumerKey, this.ConsumerSecret, token, tokenSecret
                                                 , methodName.ToString().ToUpper(), timeStamp, nonce);

            pp.Add("oauth_signature", OAuthClient.UrlEncode(si.Signature));
            //NOTE:NET2.0
            HttpClient cl = new HttpClient(HttpClient.CreateQueryString(url, pp, HttpClient.UrlEncode));

            cl.MethodName = methodName;
            return(cl);
        }
Пример #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="authorizeInfo"></param>
        /// <param name="oauthVerifier"></param>
        /// <returns></returns>
        public AccessTokenInfo GetAccessToken(AuthorizeInfo authorizeInfo, String oauthVerifier)
        {
            AuthorizeInfo ai = authorizeInfo;
            SignatureInfo si = OAuthClient.GenerateSignature(new Uri(this.AccessTokenUrl), this.ConsumerKey, this.ConsumerSecret
                                                             , ai.RequestToken, ai.RequestTokenSecret, "POST", OAuthClient.GenerateTimeStamp(), OAuthClient.GenerateNonce()
                                                             , OAuthClient.SignatureTypes.HMACSHA1);
            HttpClient cl = new HttpClient(String.Format("{0}?{1}&oauth_verifier={2}&oauth_signature={3}", this.AccessTokenUrl
                                                         , si.NormalizedRequestParameters, oauthVerifier, si.Signature));
            String s = cl.GetBodyText();

            return(AccessTokenInfo.Create(s, "oauth_token", "oauth_token_secret"));
        }