我正在使用 JanRain 的 PHP OpenID 库。它带有使用 SReg 扩展的示例脚本。但我希望它与谷歌一起工作(它实际上适用于身份验证),但谷歌使用 AX(属性交换)而不是 SReg 来获取额外数据。由于某种原因,JanRain 的库在示例脚本中缺少 AX 支持,并且 AX 脚本中的代码注释超出了我的理解,尽管 SReg 脚本中的注释清晰为 1-2-3。
有谁知道如何在没有太多痛苦的情况下实施 AX?
遇到同样的问题。AX.php 中的一些挖掘让我有了一个工作的开始。没有寻找任何错误,也没有进行过基本测试,也没有与谷歌以外的任何人进行测试。这并不漂亮:需要错误处理等。但这应该让你开始。如果我有一些强大的东西会发布更新...
第一个扔...
// oid_request.php
// Just tested this with/for Google, needs trying with others ...
$oid_identifier = 'https://www.google.com/accounts/o8/id';
// Includes required files
require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/FileStore.php";
require_once "Auth/OpenID/AX.php";
// Starts session (needed for YADIS)
session_start();
// Create file storage area for OpenID data
$store = new Auth_OpenID_FileStore('./oid_store');
// Create OpenID consumer
$consumer = new Auth_OpenID_Consumer($store);
// Create an authentication request to the OpenID provider
$auth = $consumer->begin($oid_identifier);
// Create attribute request object
// See http://code.google.com/apis/accounts/docs/OpenID.html#Parameters for parameters
// Usage: make($type_uri, $count=1, $required=false, $alias=null)
$attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/contact/email',2,1, 'email');
$attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/first',1,1, 'firstname');
$attribute[] = Auth_OpenID_AX_AttrInfo::make('http://axschema.org/namePerson/last',1,1, 'lastname');
// Create AX fetch request
$ax = new Auth_OpenID_AX_FetchRequest;
// Add attributes to AX fetch request
foreach($attribute as $attr){
$ax->add($attr);
}
// Add AX fetch request to authentication request
$auth->addExtension($ax);
// Redirect to OpenID provider for authentication
$url = $auth->redirectURL('http://localhost:4001', 'http://localhost:4001/oid_catch.php');
header('Location: ' . $url);
...然后抓住
<?php
// oid_catch.php
// Includes required files
require_once "Auth/OpenID/Consumer.php";
require_once "Auth/OpenID/FileStore.php";
require_once "Auth/OpenID/AX.php";
// Starts session (needed for YADIS)
session_start();
// Create file storage area for OpenID data
$store = new Auth_OpenID_FileStore('./oid_store');
// Create OpenID consumer
$consumer = new Auth_OpenID_Consumer($store);
// Create an authentication request to the OpenID provider
$auth = $consumer->complete('http://localhost:4001/oid_catch.php');
if ($response->status == Auth_OpenID_SUCCESS) {
// Get registration informations
$ax = new Auth_OpenID_AX_FetchResponse();
$obj = $ax->fromSuccessResponse($response);
// Print me raw
echo '<pre>';
print_r($obj->data);
echo '</pre>';
exit;
} else {
// Failed
}
这些应该是基础...
请求的一半正在工作,但是我在 Catch 中遇到了失败。
如果上面的行
$auth = $consumer->complete('http://localhost:4001/oid_catch.php');
是
$response = $consumer->complete('http://localhost:4001/oid_catch.php');
否则,响应对象从何而来?我没有在我的回复中返回 openid.current_url 来检查网址?