PHP OpenID中AX的使用示例

PHP OpenID中AX的使用示例,php,openid,janrain,Php,Openid,Janrain,我正在使用JanRain的PHP OpenID库。它附带了使用SReg扩展的示例脚本。但我希望它能与Google一起工作(实际上它也适用于auth),但是Google使用AX(属性交换)而不是SReg来获取额外的数据。出于某种原因,JanRain的库在示例脚本中缺少AX支持,我无法理解AX脚本中的代码注释,尽管SReg脚本中的注释明确为1-2-3 有人知道如何在没有太多痛苦的情况下实现AX吗?遇到了同样的问题。对AX.php的一些挖掘让我有了一个工作的开始。没有寻找任何bug,也没有在basic

我正在使用JanRain的PHP OpenID库。它附带了使用SReg扩展的示例脚本。但我希望它能与Google一起工作(实际上它也适用于auth),但是Google使用AX(属性交换)而不是SReg来获取额外的数据。出于某种原因,JanRain的库在示例脚本中缺少AX支持,我无法理解AX脚本中的代码注释,尽管SReg脚本中的注释明确为1-2-3


有人知道如何在没有太多痛苦的情况下实现AX吗?

遇到了同样的问题。对AX.php的一些挖掘让我有了一个工作的开始。没有寻找任何bug,也没有在basic之外进行测试,也没有与Google以外的任何人进行测试。这并不完美:需要错误处理等,但这应该让您开始。将发布更新,如果我有一些强大的

第一个投掷…
//  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);
。。。然后接住

//  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
}

请求的一半正在工作,但是我的捕获失败了

应该在上面划线吗

$response = $consumer->complete('http://localhost:4001/oid_catch.php');

否则,响应对象从何而来?
我的回复中没有返回openid.current\u url以检查url?

我如何使其与yahoo一起工作。。?请帮忙。谢谢,如果你能回去对下面建议的答案进行更正,那就很方便了。(consumer->complete行也缺少了一个'在语法高亮显示中显示:)如果我能工作得很好,我会给你+100,谢谢!唯一的问题是从
Auth\u OpenID\u AX\u FetchResponse
读取值的正确方法——有一个访问器方法,但它对我来说不太管用。你可能早就解决了这个问题,但对其他人来说,请注意这里没有结束引用。编辑到帖子中。雅虎的问题解决了!!!检查这里:注意,您可以将AX和SReg放在一起,提供商将填写他们支持/喜欢的内容(或者两者都支持,或者两者都不支持)。