Пример #1
0
        /// <summary>
        /// Generates a signature using the specified signatureType
        /// </summary>
        /// <param name="url">The full url that needs to be signed including its non OAuth url parameters</param>
        /// <param name="consumerKey">The consumer key</param>
        /// <param name="consumerSecret">The consumer seceret</param>
        /// <param name="token">The token, if available. If not available pass null or an empty String</param>
        /// <param name="tokenSecret">The token secret, if available. If not available pass null or an empty String</param>
        /// <param name="httpMethod">The http method used. Must be a valid HTTP method verb (POST,GET,PUT, etc)</param>
        /// <param name="nonce"></param>
        /// <param name="signatureType">The type of signature to use</param>
        /// <param name="timeStamp"></param>
        /// <returns>A base64 String of the hash value</returns>
        public static SignatureInfo GenerateSignature(Uri url, String consumerKey, String consumerSecret, String token, String tokenSecret, String httpMethod, String timeStamp, String nonce, SignatureTypes signatureType)
        {
            SignatureInfo si = new SignatureInfo();

            switch (signatureType)
            {
            case SignatureTypes.PLAINTEXT:
                si.Signature = OAuthClient.UrlEncode(String.Format("{0}&{1}", consumerSecret, tokenSecret));
                return(si);

            case SignatureTypes.HMACSHA1:
                si = GenerateSignatureBase(url, consumerKey, token, httpMethod, timeStamp, nonce, Key.HMACSHA1SignatureType);
                HMACSHA1 hs = new HMACSHA1();
                hs.Key       = OAuthClient.GenerateSignatureEncoding.GetBytes(String.Format("{0}&{1}", OAuthClient.UrlEncode(consumerSecret), String.IsNullOrEmpty(tokenSecret) ? "" : OAuthClient.UrlEncode(tokenSecret)));
                si.Signature = GenerateSignatureUsingHash(si.Signature, hs);
                return(si);

            case SignatureTypes.RSASHA1:
                throw new NotImplementedException();
            }
            throw new ArgumentException("Unknown signature type", "signatureType");
        }
Пример #2
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"));
        }