private SortedDictionary <string, string> GetOAuthHeaderParameters(string requestUrl)
        {
            SortedDictionary <string, string> sortedParameters = new SortedDictionary <string, string>();

            _oauthHeader.Nonce     = OAuthHelper.GenerateNonce();
            _oauthHeader.Timestamp = OAuthHelper.GenerateTimeStamp();

            sortedParameters.Add("oauth_consumer_key", _oauthHeader.ConsumerKey);
            sortedParameters.Add("oauth_token", _oauthHeader.AccessToken);
            sortedParameters.Add("oauth_signature_method", _oauthHeader.SignatureMethod);
            sortedParameters.Add("oauth_version", _oauthHeader.Version);
            sortedParameters.Add("oauth_timestamp", _oauthHeader.Timestamp);
            sortedParameters.Add("oauth_nonce", _oauthHeader.Nonce);

            Dictionary <string, string> queryParameters = UriHelper.GetQueryParameters(requestUrl);

            foreach (var queryParameter in queryParameters)
            {
                sortedParameters.Add(queryParameter.Key, queryParameter.Value);
            }

            return(sortedParameters);
        }
        private string GetDisqusCommentsScript()
        {
            var sb = new StringBuilder(50);
            FeatureController ctlModule = new FeatureController();

            AppendToStringBuilder(ref sb, "<div id=\"disqus_thread\"></div> ");
            AppendToStringBuilder(ref sb, "<script type=\"text/javascript\" language=\"javascript\"> ");

            // generate SSO stub for Disqus
            if (DisqusSsoEnabled && !string.IsNullOrEmpty(DisqusSsoApiKey))
            {
                //AppendToStringBuilder(ref sb, "<script type=\"text/javascript\" language=\"javascript\"> ");
                AppendToStringBuilder(ref sb, "var disqus_config = function() { ");

                OAuthHelper auth = new OAuthHelper();
                string strMessage = GetSsoMessage();
                string strHmac = GetSsoHmac(strMessage, auth.GenerateTimeStamp());
                string strPayload = string.Format("this.page.remote_auth_s3 = '{0} {1} {2}'; ", strMessage, strHmac, auth.GenerateTimeStamp());

                AppendToStringBuilder(ref sb, strPayload);

                string strApiKey = string.Format("this.page.api_key = '{0}'; ", DisqusSsoApiKey);
                AppendToStringBuilder(ref sb, strApiKey);

                AppendToStringBuilder(ref sb, "}; ");
                //AppendToStringBuilder(ref sb, "</script> ");
            }

            //sb.Append("/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */");
            if (DisqusDeveloperMode == true)
            {
                AppendToStringBuilder(ref sb, "var disqus_developer = 1; ");
            }
            else
            {
                AppendToStringBuilder(ref sb, "var disqus_developer = 0; ");
            }
            string strShortName = string.Format("var disqus_shortname = '{0}'; ", DisqusApplicationName);
            AppendToStringBuilder(ref sb, strShortName);

            //sb.Append("// The following are highly recommended additional parameters. Remove the slashes in front to use.");
            // need to parse for isolated views in DNN and add them to this identifier
            string strIdentifier = string.Format("var disqus_identifier = '{0}'; ", ctlModule.CreateUniqueIdentifier(TabId, TabModuleId, PortalSettings.GUID, Request.RawUrl));
            AppendToStringBuilder(ref sb, strIdentifier);
            AppendToStringBuilder(ref sb, "var disqus_url = document.URL; ");

            //sb.Append("/* * * DON'T EDIT BELOW THIS LINE * * */");
            AppendToStringBuilder(ref sb, "(function() { ");
            AppendToStringBuilder(ref sb, "var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; ");
            AppendToStringBuilder(ref sb, "dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; ");
            AppendToStringBuilder(ref sb, "(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); ");
            AppendToStringBuilder(ref sb, "})();");
            AppendToStringBuilder(ref sb, "</script>");
            AppendToStringBuilder(ref sb, "<noscript>Please enable JavaScript to view the <a href=\"http://disqus.com/?ref_noscript\">comments powered by Disqus.</a></noscript>");
            AppendToStringBuilder(ref sb, "<!--<a href=\"http://disqus.com\" class=\"dsq-brlink\">blog comments powered by <span class=\"logo-disqus\">Disqus</span></a>-->");

            return sb.ToString();
        }
        /// <summary>
        /// Gets a signed Uri for the specified endpoint with the specified parameters appended to the query string.
        /// This Uri can be used with REST APIs that use OAuth.
        /// </summary>
        /// <param name="url">The url that will have the parameters appended to its query string</param>
        /// <param name="key">OAuth key required by the external system</param>
        /// <param name="secret">OAuth secret required by the external system</param>
        /// <param name="parameters">The keys and values that are appended to the query string</param>
        /// <returns>A signed Uri for the endpoint with the parameters appended to the query string</returns>
        protected virtual Uri GetSignedUri(string url, string key, string secret, IDictionary<string, string> parameters)
        {
            var uri = GetUri(url, parameters);
            string nurl, nreq;
            var oAuth = new OAuthHelper();

            var nounce = oAuth.GenerateNonce();
            var timestamp = oAuth.GenerateTimeStamp();

            var signatureUrl = oAuth.GenerateSignature(
                url: uri,
                consumerKey: key,
                consumerSecret: secret,
                token: string.Empty,
                tokenSecret: string.Empty,
                httpMethod: "GET",
                timeStamp: timestamp,
                nonce: nounce,
                signatureType: OAuthHelper.SignatureTypes.HMACSHA1,
                normalizedUrl: out nurl,
                normalizedRequestParameters: out nreq);

            signatureUrl = HttpUtility.UrlEncode(signatureUrl);

            var parameters2 = new Dictionary<string, string>();
            parameters2.Add("oauth_consumer_key", key);
            parameters2.Add("oauth_nonce", nounce);
            parameters2.Add("oauth_timestamp", timestamp);
            parameters2.Add("oauth_signature_method", "HMAC-SHA1");
            parameters2.Add("oauth_version", "1.0");
            parameters2.Add("oauth_signature", signatureUrl);
            var uri2 = GetUri(uri.ToString(), parameters2, true);
            return uri2;
        }