所以我试图掌握OpenID,我觉得我理解了这个理论,等等......现在它开始实现它了。我有一个非常基本的设置,可以向谷歌提供商地址发送一个卷曲请求。
https://www.google.com/accounts/o8/id
解析返回的 XRDS XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)">
<XRD>
<Service priority="0">
<Type>http://specs.openid.net/auth/2.0/server</Type>
<Type>http://openid.net/srv/ax/1.0</Type>
<Type>http://specs.openid.net/extensions/ui/1.0/mode/popup</Type>
<Type>http://specs.openid.net/extensions/ui/1.0/icon</Type>
<Type>http://specs.openid.net/extensions/pape/1.0</Type>
<URI>https://www.google.com/accounts/o8/ud</URI>
</Service>
</XRD>
</xrds:XRDS>
从他们的 XRDS 文档中检索谷歌的实际提供商后,我使用此功能重定向......
public function RedirectToEndpoint() {
$params = array();
$params['openid.mode'] = 'checkid_setup';
$params['openid.ns'] = 'http://specs.openid.net/auth/2.0';
$params['openid.claimed_id'] = 'http://specs.openid.net/auth/2.0/identifier_select';
$params['openid.identity'] = 'http://specs.openid.net/auth/2.0/identifier_select';
$params['openid.return_to'] = $this->URLs['return_to'];
$params['openid.realm'] = $this->URLs['realm'];
$join = stripos($this->URLs['openid_server'], '?') ? '&' : '?';
$redirect_to = $this->URLs['openid_server'] . $join . $this->array2url($params);
if (headers_sent()){ // Use JavaScript to redirect if content has been previously sent (not recommended, but safe)
echo '<script language="JavaScript" type="text/javascript">window.location=''';
echo $redirect_to;
echo ''';</script>';
}else{ // Default Header Redirect
header('Location: ' . $redirect_to);
}
}
array2url 是一个简单的函数,它将 assoc 数组$params转换为附加到查询字符串。
生成的网址是这样的...
https://www.google.com/accounts/o8/ud?openid.mode=checkid_setup&openid.ns=http://specs.openid.net/auth/2.0&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select&openid.identity=http://specs.openid.net/auth/2.0/identifier_select&openid.return_to=http://learn.local/openid/return.php&openid.realm=http://learn.local/openid/index.html&
但是,您最终到达的页面请求无效。还有一个不错的 400 个错误请求..有什么想法吗?
总而言之,我感觉自己再愚蠢不过了!归根结底是正确设置我的领域。我有一个领域,导致我的回信地址超出了可用的"范围",可以这么说。对于将来遇到 400 错误的人来说,它可能是......
$openid->SetReturnAddress(('http://learn.local/openid/return.php')); //.return_to
$openid->SetDomain(('http://learn.local/openid/index.html')); //Realm
配置不佳的领域。脸掌
就是现在...
$openid->SetDomain(('http://learn.local')); //Realm