从gmail获取属性-OpenID身份验证
-
11-10-2019 - |
题
我正在利用Lightopenid,并且正在尝试获得此Gmail身份验证的属性,但是它似乎没有返回我的个人帐户上的任何内容,也没有错误。我是OpenID的新手,希望有人可以帮助我以前做过谁。
我正在指定字段 validate()
并归还他们 process()
我正在使用OpenID URL: https://www.google.com/accounts/o8/id
public function show () {
if ($this->site->tru->post->isRequest() || !$this->site->tru->get->isEmpty('openid_mode')) {
require_once $this->site->tru->config->get('root.path').'/lib/php/openid.php';
$this->lightOpenId = new LightOpenID;
if ($this->validate() || $this->lightOpenId->validate()) {
$this->process();
}
}
$this->site->addCss('account/login.css');
$this->site->addJs('account/login.js');
echo $this->site->tru->display->getTemplate('/site/account/login.tpl');
}
public function process () {
if ($this->lightOpenId->validate()) {
echo '<pre>'.print_r($this->lightOpenId).'
'.print_r($this->lightOpenId->getAttributes()).'</pre>';
}
}
public function validate () {
if (!$this->site->tru->post->isEmpty('openid_url')) {
$this->lightOpenId->identity = $this->site->tru->post->get('openid_url');
$this->lightOpenId->optional = array('contact/email', 'namePerson', 'contact/postalCode/home', 'contact/country/home');
header('Location: '.$this->lightOpenId->authUrl());
}
return count($this->error) == 0;
}
解决方案
Google仅回答所需参数,完全忽略了可选参数。
另外,它只能返回以下属性:
contact/country/home
contact/email
namePerson/first
namePerson/last
pref/language
所以 namePerson
和 contact/postalCode/home
行不通。
以上信息特定于Google,并且与Lightopenid本身完全无关。
至于图书馆,我建议不要两次调用$ lightopenid-> validate()。每次致电时,它都会向提供者发送请求,该请求可能会拒绝第二个请求。
其他提示
$openid->identity = 'https://www.google.com/accounts/o8/';
// use the following line to obtain the required details. These are the only details that google mail provides. This is for lightopenid.
$openid->required = array('namePerson/friendly', 'contact/email' , 'contact/country/home', 'namePerson/first', 'pref/language', 'namePerson/last');
header('Location: ' . $openid->authUrl());
不隶属于 StackOverflow