0

我有这个修改过的 lightOpenId 的谷歌示例连接代码:

<?php
require_once('../db.php');
session_start();
# Logging in with Google accounts requires setting special identity, so this example shows how to do it.
require 'openid.php';
try {
    # Change 'localhost' to your domain name.
    $openid = new LightOpenID('127.0.0.1');
    if(!$openid->mode) {
        if(isset($_GET['login'])) {
            $openid->identity = 'https://www.google.com/accounts/o8/id';
            $openid->required = array('contact/email');
            $openid->optional = array('namePerson', 'namePerson/friendly');
            header('Location: ' . $openid->authUrl());
        }
?>
<form action="?login" method="post">
    <button>Login with Google</button>
</form>
<?php
    } elseif($openid->mode == 'cancel') {
        echo 'User has canceled authentication!';
    } else {
        if ($openid->validate()) {
            $_SESSION['auth'] = $openid->identity;

            $userinfo = $openid->getAttributes();
            print_r($openid->required);
            echo $_SESSION['auth'];

            $stmt = $dbh->prepare("INSERT INTO users(id,name,email) VALUES(:id,:name,:email)");
            $stmt->execute(array(":id" => $openid->identity,
                                ":name" => "name",
                                ":email" => "name"));
        }
    }
} catch(ErrorException $e) {
    echo $e->getMessage();
}

我的问题是 $openid->required 不返回任何东西。数组本身甚至不包含一个空的“联系人/电子邮件”字段。我在这里做错了什么?

4

1 回答 1

0

$openid->required在请求之间不会保留,但您不必使用它。

至于为$userinfo空,它只包含提供者返回的字段(例如,没有字段),无论您请求什么。

提供者可能会返回您请求的字段,但它不必,甚至不必支持返回任何附加数据(因为这是协议扩展)。

于 2013-04-12T11:15:19.530 回答