LightOpenID在默认设置中给出错误,在有效登录时返回false



使用LightOpenID类,我正在尝试将谷歌的登录与我的网站集成。我使用默认代码:

<?php
require 'includes/openid.php';
try {
    if(!isset($_GET['openid_mode'])) {
        if(isset($_GET['login'])) {
            $openid = new LightOpenID;
            $openid->identity = 'https://www.google.com/accounts/o8/id';
            header('Location: ' . $openid->authUrl());
        }
?>
<form action="?login" method="post">
    <button>Login with Google</button>
</form>
<?php
    } elseif($_GET['openid_mode'] == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        $openid = new LightOpenID;
        echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}
echo '<pre>'.print_r($openid,true).'</pre>';
?>

最初,这告诉我construct方法缺少参数1,迫使我将new LightOpenID方法调用为new LightOpenID($host)。但由于我已经更改了它并尝试登录,当我恢复代码时,它并没有给出错误,只是去获取错误。。。

不管怎样,抛开这一点不谈,在我添加主机后,我被带到谷歌页面,它问我是否想用我的谷歌帐户登录该网站。我按下了登录按钮,然后被带回去,却被告知我没有登录。

User has not logged in.
LightOpenID Object
(
    [returnUrl] => myReturnURL
    [required] => Array
        (
        )
    [optional] => Array
        (
        )
    [verify_peer] => 
    [capath] => 
    [cainfo] => 
    [data] => Array
        (
            [login] => 
            [openid_ns] => http://specs.openid.net/auth/2.0
            [openid_mode] => id_res
            [openid_op_endpoint] => https://www.google.com/accounts/o8/ud
            [openid_response_nonce] => 2012-07-23T14:06:24ZQwlS1zWFRdvg6A
            [openid_return_to] => myReturnURL
            [openid_assoc_handle] => AMlYA9WMwp_rTkH3swNLEF5UASFvhyOR-kqVSXGe7cvXe7ws5z8HHWUu
            [openid_signed] => op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle
            [openid_sig] => NtOEY8dUM1Hpt2tTR9x0RdN5o1c=
            [openid_identity] => https://www.google.com/accounts/o8/id?id=AItOawkXNCi5qq-3Vj_esgSQAwmEN_nVIC8BHAQ
            [openid_claimed_id] => https://www.google.com/accounts/o8/id?id=AItOawkXNCi5qq-3Vj_esgSQAwmEN_nVIC8BHAQ
        )
    [identity:LightOpenID:private] => 
    [claimed_id:LightOpenID:private] => https://www.google.com/accounts/o8/id?id=AItOawkXNCi5qq-3Vj_esgSQAwmEN_nVIC8BHAQ
    [server:protected] => https://www.google.com/accounts/o8/ud
    [version:protected] => 2
    [trustRoot:protected] => mySite
    [aliases:protected] => 
    [identifier_select:protected] => 
    [ax:protected] => 1
    [sreg:protected] => 
    [setup_url:protected] => 
    [headers:protected] => Array
        (
            [cache-control] => no-cache, no-store, max-age=0, must-revalidate
            [pragma] => no-cache
            [expires] => Fri, 01 Jan 1990 00:00:00 GMT
            [date] => Mon, 23 Jul 2012 14:06:26 GMT
            [content-type] => text/plain; charset=UTF-8
            [x-content-type-options] => nosniff
            [x-frame-options] => SAMEORIGIN
            [x-xss-protection] => 1; mode=block
            [server] => GSE
        )
)

我已经登录了谷歌,所以谷歌页面没有要求我登录,只是为了验证我是否想使用我的谷歌帐户登录自己的网站。有人明白为什么它没有说我已经登录了吗?

提前谢谢。

使用最新版本,它应该可以工作。

只需记住,库的较新版本需要构造函数中的一个参数:

$openid = new LightOpenId('www.domain.com');

相关内容

  • 没有找到相关文章

最新更新