我需要使用谷歌的OpenID功能,我尝试了Steven的代码,但无法直接使用。我做了一些修改。
_discovery更改的方法仍然相同:
在Zend/OpenId/Consumer.php文件的第765行添加:
} else if (preg_match('/<URI>([^<]+)<\/URI>/i', $response, $r)) {
$version = 2.0;
$server = $r[1];
其余部分有所不同:
在进行上述更改后,Zend/OpenId/Consumer.php文件的第859行添加如下内容:
if (stristr($server, 'https://www.google.com/') !== false) {
$id = 'http://specs.openid.net/auth/2.0/identifier_select';
$claimedId = 'http://specs.openid.net/auth/2.0/identifier_select';
}
这是之前的内容:
$params['openid.identity'] = $id;
$params['openid.claimed_id'] = $claimedId;
一旦获得授权,要使其返回ID:
Zend/Auth/Adapter/OpenId.php,第278行:
if(isset($_REQUEST['openid_identity']))
{
$this->_id = $_REQUEST['openid_identity'];
$id = $this->_id;
}
这是之前的内容:
return new Zend_Auth_Result(
Zend_Auth_Result::SUCCESS,
$id,
array("Authentication successful"));
请注意,我没有彻底测试过这段代码。以下代码更加不稳定。
我花费了更多时间,并通过以下更改使其与我的Google Apps域名一起工作:
Zend/OpenId/Consumer.php,第734行。
$discovery_url = $id;
if(strpos($discovery_url, '/', strpos($discovery_url, '//')+2) !== false) {
$discovery_url = substr($discovery_url, 0, strpos($discovery_url, '/', strpos($discovery_url, '//')+2));
}
$discovery_url .= '/.well-known/host-meta';
$response = $this->_httpRequest($discovery_url, 'GET', array(), $status);
if ($status === 200 && is_string($response)) {
if (preg_match('/Link: <([^><]+)>/i', $response, $r)) {
$id = $r[1];
}
}
这是紧接着的内容:
/* TODO: OpenID 2.0 (7.3) XRI and Yadis discovery */
我相信这是我需要做出的唯一更改。我很确定上述内容应该包括一些安全检查,但我还没有深入研究过它们会是什么。