Exemplo n.º 1
0
        static private String GenerateSignedUrl(String baseRequestTokenUrl, String method, OAuthConsumerContext context, OAuthToken token)
        {
            String normalizedUrl;
            String normalizedRequestParameters;

            var oAuth = new OAuthBase();

            string nonce     = oAuth.GenerateNonce();
            string timeStamp = oAuth.GenerateTimeStamp();
            string sig       = oAuth.GenerateSignature(new Uri(baseRequestTokenUrl),
                                                       context.ConsumerKey, context.ConsumerSecret,
                                                       token == null ? string.Empty : token.TokenKey, token == null ? string.Empty : token.TokenSecret,
                                                       method.ToString(), timeStamp, nonce,
                                                       context.SignatureMethod,
                                                       out normalizedUrl, out normalizedRequestParameters);

            //
            // The signature as self has to be encoded to be ensure that no not url compatibale characters
            // will be used. The SHA1 hash can contain a bunch of this characters
            //
            sig = HttpUtility.UrlEncode(sig);

            var sb = new StringBuilder(normalizedUrl);

            sb.AppendFormat("?");
            sb.AppendFormat(normalizedRequestParameters);
            sb.AppendFormat("&oauth_signature={0}", sig);

            return(sb.ToString());
        }