Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="tokenKey"></param>
        /// <param name="tokenSecretKey"></param>
        /// <returns></returns>
        public static AccessTokenInfo Create(String value, String tokenKey, String tokenSecretKey)
        {
            AccessTokenInfo t = new AccessTokenInfo("", "");

            String[] ss  = value.Split('&');
            String[] sss = null;
            Dictionary <String, String> d = new Dictionary <string, string>();

            for (int i = 0; i < ss.Length; i++)
            {
                if (ss[i].Contains("=") == false)
                {
                    continue;
                }
                sss = ss[i].Split('=');
                if (sss.Length == 2)
                {
                    d[sss[0].ToLower()] = sss[1];
                }
            }
            t._Values = d;
            if (d.ContainsKey(tokenKey) == true)
            {
                t.Token = d[tokenKey];
            }
            if (d.ContainsKey(tokenSecretKey) == true)
            {
                t.TokenSecret = d[tokenSecretKey];
            }
            return(t);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="authorizeInfo"></param>
        /// <param name="oauthVerifier"></param>
        /// <returns></returns>
        public AccessTokenInfo GetAccessToken(AuthorizeInfo authorizeInfo, String oauthVerifier)
        {
            var ai = authorizeInfo;
            var cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret
                                                , ai.RequestToken, ai.RequestTokenSecret, HttpMethodName.Post);
            var si = OAuthClient.GenerateSignature(new Uri(this.AccessTokenUrl), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command = new HttpRequestCommand(String.Format("{0}?{1}&oauth_verifier={2}&oauth_signature={3}"
                                                                              , this.AccessTokenUrl, si.NormalizedRequestParameters, oauthVerifier, si.Signature), HttpMethodName.Post);
            HttpClient cl = new HttpClient();
            String     s  = cl.GetBodyText(command);

            return(AccessTokenInfo.Create(s, "oauth_token", "oauth_token_secret"));
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <returns></returns>
        public AccessTokenInfo GetAccessToken(String requestToken, String requestTokenSecret)
        {
            String url = this.AccessTokenUrl;
            GetRequestTokenCommand cm = new GetRequestTokenCommand(this.ConsumerKey, this.ConsumerSecret
                                                                   , requestToken, requestTokenSecret, HttpMethodName.Post);
            SignatureInfo      si      = OAuthClient.GenerateSignature(new Uri(url), cm, OAuthSignatureTypes.HMACSHA1);
            HttpRequestCommand command =
                new HttpRequestCommand(String.Format("{0}?{1}&oauth_signature={2}", url, si.NormalizedRequestParameters, si.Signature), HttpMethodName.Post);
            HttpClient cl     = new HttpClient();
            String     result = cl.GetBodyText(command);

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