0

lightOpenId のこの変更された google-example 接続コードがあります。

<?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 に答える