Disqus上的问题单点登录,没有连接

时间:2013-05-20 21:37:30

标签: php disqus

我正在尝试实施disqus单点登录,但我似乎无法建立连接,我设置了一个测试页:

<?php
define('DISQUS_SECRET_KEY', 'mykey');
define('DISQUS_PUBLIC_KEY', 'myotherkey');

$data = array(
    "username" => "Disqus Test",
    "url" => "http://disqus.com",
    "id" => "999",
    "avatar" => "http://dl.dropbox.com/u/31679327/Screenshots/30v.png",
    "email" => "disqus-test@disqus.com"
);

function dsq_hmacsha1($data, $key) {
    $blocksize=64;
    $hashfunc='sha1';
    if (strlen($key)>$blocksize)
    $key=pack('H*', $hashfunc($key));
    $key=str_pad($key,$blocksize,chr(0x00));
    $ipad=str_repeat(chr(0x36),$blocksize);
    $opad=str_repeat(chr(0x5c),$blocksize);
    $hmac = pack('H*',$hashfunc(
    ($key^$opad).pack('H*',$hashfunc(
    ($key^$ipad).$data)
    )
    )
    );
return bin2hex($hmac);
}

$message = base64_encode(json_encode($data));
$timestamp = time();
$hmac = dsq_hmacsha1($message . ' ' . $timestamp, DISQUS_SECRET_KEY);
?>

<!DOCTYPE HTML>
<html>
<head>
<title>Test Site</title>
</head>
<body>

<div id="disqus_thread"></div>

<script type="text/javascript">
var disqus_config = function() {
this.page.remote_auth_s3 = "<?php echo "$message $hmac $timestamp"; ?>";
this.page.api_key = "<?php echo DISQUS_PUBLIC_KEY; ?>";
}

/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'funkydic'; // required: replace example with your forum shortname

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

<?php echo "$message $hmac $timestamp"; ?>
</body>
</html>

我解码了有效载荷,看起来应该是这样,问题似乎在于连接,即使所有内容看起来都像它应该设置的那样。

任何帮助都是apriciated

1 个答案:

答案 0 :(得分:0)

看起来您的实际代码很好,这几乎肯定是应用程序配置错误或不正确放置的javascript变量。

第一步是查看本文档,该文档介绍了最常见的问题:http://help.disqus.com/customer/portal/articles/1148640

特别检查以确保X-Disqus-Remote-Auth标头在请求中进行。

如果所有这些都结帐,请发布包含公钥的页面的完整源代码(它只适用于您指定的域名),我们可以查看是否还有其他错误