我刚刚发现了LightOpenID,我认为它很棒。我已经设法使用以下修改获得了电子邮件地址、名字和姓氏以及首选语言example-gmail.php
:
<?php
require_once('openid.php');
if (empty($_GET['openid_mode']))
{
if (isset($_GET['login']))
{
$openid = new LightOpenID();
$openid->identity = 'https://www.google.com/accounts/o8/id';
$openid->required = array('namePerson/first', 'namePerson/last', 'contact/email', 'pref/language');
header('Location: ' . $openid->authUrl());
//header('Location: ' . str_replace('&', '&', $openid->authUrl()));
}
else
{
echo '<form action="?login" method="post">' . "\n";
echo '<button>Login with Google</button>' . "\n";
echo '</form>' . "\n";
}
}
else if ($_GET['openid_mode'] == 'cancel')
{
echo 'User has canceled authentication!';
}
else
{
$openid = new LightOpenID();
echo 'User ' . ($openid->validate() ? $_GET['openid_identity'] . ' has ' : 'has not ') . 'logged in.';
echo '<pre>';
print_r($openid->getAttributes());
echo '</pre>';
}
?>
我更改了代码以使其更具可读性,输出:
User https://www.google.com/accounts/o8/id?id=*** has logged in.
Array
(
[namePerson/first] => Alix
[contact/email] => ***@gmail.com
[pref/language] => en
[namePerson/last] => Axel
)
我仍然无法从 Google 获得邮政编码和其他信息,但我在myOpenID.com上取得了成功。