Использование в качестве примера AX в PHP OpenID

<img src="http://localhost:5001/"/>

Выше недопустимо, потому что вы загружаете корень той страницы, которая возвращает HTML.

Вы должны ссылаться на него примерно так:

<img src='http://localhost:5001/static/image1.png' />

Если это не сработает, снова загрузите рабочее изображение и щелкните правой кнопкой мыши, чтобы просмотреть на новой вкладке, отметив правильный URL-адрес и замените его здесь.

25
задан Jan B. Kjeldsen 25 May 2011 в 11:21
поделиться

2 ответа

Половина запроса работает, однако в Catch происходит сбой.

Должна ли строка выше

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

быть

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

В противном случае, откуда берется объект ответа? Я не вернул openid.current_url в своем ответе, чтобы проверить URL с помощью?

4
ответ дан crb 28 November 2019 в 20:51
поделиться

Решили ту же проблему. Немного покопавшись в AX.php, я начал работать. Не искал никаких ошибок, не проверял, кроме базового, и не тестировал ни с кем, кроме 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);

... а потом поймать

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

Это должно быть основой ...

45
ответ дан 28 November 2019 в 20:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: