AX的实施例的使用在PHP的OpenID(Example usage of AX in PHP Op

2019-06-26 20:07发布

我使用Janrain的PHP OpenID库。 它配备了哪些使用SREG扩展示例脚本。 但我想它与谷歌合作(和它的作品是面向auth实际上),但谷歌使用AX(属性交换),而不是SREG的额外数据。 出于某种原因,Janrain的库缺少AX支持在示例脚本,并在AX脚本代码中的注释也不在我的理解,尽管在SREG脚本注释是明确为1-2-3。

有谁知道如何实现AX没有太多的痛苦吗?

Answer 1:

遇到同样的问题。 在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
}

这些应该是基本...



Answer 2:

请求一半的工作,但是我在catch越来越失效。

首先应行

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

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

否则,哪里响应对象从何而来? 我没有收到返回的openid.current_url在我的回应与查询的网址?



文章来源: Example usage of AX in PHP OpenID