2016-06-19 6 views
12

좋아, 이건 좀 복잡해. 그러니 나와 곰.PHPBB3 인증을 사용하여 Zend2 애플리케이션을 통합하는 올바른 방법은 무엇입니까?

저는 얼마 전 PHPBB 포럼을 운영하고 있습니다. 제 목표는 완전히 새로운 인증 구성 요소를 구축하는 대신 사용자 관리 및 인증 기능을 사용하여 Zend2 PHP 응용 프로그램을 만드는 것입니다. 다시 포럼.

라이브 환경에서 다음 구성 요소가 사용됩니다 : PHPBB3, Zend Framework 2 (최신 안정 버전), Apache, PHP 5.6 이상, MySQL은 루트 액세스없이 가상 Linux 서버에서 실행됩니다.

내 개발 환경 (아래의 모든 예제를 실행하는)입니다 : PHPBB3는, 젠드 프레임 워크 2 (최신 안정), XAMPP 3.2.2, Xdebug는과 PHP 5.6.21 활성화, MariaDB는

윈도우 8에서 실행 이미 프레임 워크를 사용하지 않고 직접 아약스를 통해 PHP를 호출을 포함하여 성공을 거두었습니다

global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template; 
define('IN_PHPBB', true); 
$phpbb_root_path = './forum/phpBB3/'; // this path is from an external example 
$phpEx = substr(strrchr(__FILE__, '.'), 1); 
$phpBBFile = $phpbb_root_path . 'common.' . $phpEx; 
include($phpBBFile); 

// Start session management 
$user->session_begin(); 
$auth->acl($user->data); 
$user->setup(); 

을,하지만 지금 - 젠드이 프레임 워크를 사용하여 : PHPBB의 통합이 다음 줄을 요청 할 때마다 필연적으로 검색에 올려 - n을 포함 할 때 여러 가지 문제가 발생합니다. ative PHPBB3 코드.

필자는 경험 많은 PHP 프로그래머가 아니며 지금은 며칠 동안 젠드에 대해 배우고있다. 젠드 신청 전에 위의 코드를 통합하는 중심

내 첫 번째 시도는 Zends index.php에서 호출됩니다

Catchable fatal error: Argument 1 passed to Zend\Stdlib\Parameters::__construct() must be of the type array, object given, called in C:\xampp\htdocs\myZendApp\vendor\zendframework\zend-http\src\PhpEnvironment\Request.php on line 72 and defined in C:\xampp\htdocs\myZendApp\vendor\zendframework\zend-stdlib\src\Parameters.php on line 24

그래서 PHPBB를 호출이 초기에 보인다

.... 
// Setup autoloading 
require 'init_autoloader.php'; 

global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template; 
define('IN_PHPBB', true); 
$phpbb_root_path = 'public/forums/'; 
$phpEx = substr(strrchr(__FILE__, '.'), 1); 
$phpBBFile = $phpbb_root_path . 'common.' . $phpEx; 
include($phpBBFile); 

// Run the application! 
Zend\Mvc\Application::init(require 'config/application.config.php')->run(); 
.... 

이 오류가 발생합니다 엉망진창 젠드, 다른 구현 방법에 대해서 나쁘게 생각해.

내가 선호하는 디자인에는 PHPBB 인증을 처리하고 모든 경로와 해당 컨트롤러의 서비스로 사용할 수있는 별도의 인증 젠드 모듈이 포함됩니다. 그러나 phpbb 스크립트를 포함하고 호출하는 것은 아마도 전역 적으로 많이 사용하는 것과 관련된 여러 가지 문제를 일으킬 수 있습니다. 여기

몇 가지 예를 상기 PhpbbAuthController에서 checkAction의 코드 : 그것으로 디버깅 후 session_begin()

Fatal error: Call to a member function header() on null in C:\xampp\htdocs\myZendApp\public\forums\phpbb\session.php on line 228

을 실행에서 여기

public function checkAction(){ 
    global $phpbb_root_path, $phpEx, $user, $db, $config, $cache, $template; 
    define('IN_PHPBB', true); 
    $phpbb_root_path = 'public/forums/'; 
    $phpEx = substr(strrchr(__FILE__, '.'), 1); 
    $phpBBFile = $phpbb_root_path . 'common.' . $phpEx; 
    include($phpBBFile); 

    $user->session_begin(); 
    $auth->acl($user->data); 
    $user->setup(); 

    $response = array(); 
    if ($user->data['user_id'] == ANONYMOUS) { 
     $response['loginState'] = "logged_out"; 
    } else { 
     $response['loginState'] = "logged_in"; 
    } 
    return new ViewModel($response); 
} 

그리고 오류가 보였다 그 $ 요청에 대한 모든 참조 및 해당 인증 함수 내에서 $ symfony_request는 NULL입니다.

젠드 컨텍스트에서 스크립트를 실행하는 방법을 식별하는 데 많은 시간을 허비 한 후에는 별도의 컨텍스트에서 스크립트를 실행하는 방식으로 눈을 떴습니다. 내 마음에 가장 쉬운 방법은 HttpClient에서 스크립트를 호출하고 결과 텍스트를 사용하여 인증 서비스를 실행하는 것입니다. 이렇게하려면 호출 된 스크립트에서 세션 쿠키를 검색하여 Zend 응용 프로그램에서 사용할 수 있도록 저장해야합니다.

젠드 프레임 워크를 통해 스크립트를 전송하면 젠드 컨트롤러에서 PHBB 코드를 사용하여 같은 문제가 다시 발생하는 것처럼 보이므로 Zends 라우팅을 사용하여 액세스 할 수 없습니다. http 요청을 사용하고 있기 때문에 스크립트를 공용 디렉토리 나 하위 디렉토리에 저장해야합니다.

그리고 그것이 바로 지금입니다. PHPBB를 사용하는 php 파일에 대한 내부 호출은 독자적으로 작동하지만 HttpClient (지금은 Zend Controller 클래스에서 사용)은 매회마다 시간 제한을 실행합니다. 여기에서 또 다른 질문으로 공식화했습니다 : Zend 2 Http Client Request times out when requesting php file from localhost/public directory.

나는 당신의 의견, 힌트 및 가능한 아키텍처 또는 심지어 위에서 언급 한 내 문제에 대한 부분 솔루션을 주셔서 감사합니다.

필자가 어떤 상황에서도하고 싶지 않은 것은 이미 PHPBB에 있으며 장기적으로 보안 문제로 이어지는 복잡하지만 입증 된 시스템보다 항상 열악한 내 자신의 인증 및 사용자 관리를 개발하는 것입니다. 젠드 애플리케이션은 포럼이 현재 상황의 핵심이기 때문에 "엑스트라"로 간주됩니다.

시간 내 주셔서 감사 드리며 추가 정보를 요청하십시오. (나는 모든 코드를 포함 할 수 없었고이 시점에서 당신에게 어떤 관련이 있을지 모르겠습니다.)

+0

내가하고 싶은 일을 완전히 벗어난 경우에도 귀하의 의견을 듣고 싶습니다. 내가 처분 할 수있는 자원이 매우 부족합니다. 이는 기존 솔루션을 내 응용 프로그램에 통합하려는 가장 중요한 이유입니다. – elfwyn

+0

내 대답을 아래에서보십시오. 나는 그것이 유용하다고 생각한다. – vpassapera

답변

2

PHPBB 3.x는 심포니 컴포넌트를 사용합니다. 참조하는 소식은 지극히 오래된 것입니다. https://github.com/phpbb/phpbb/blob/3.1.x/phpBB/config/auth.yml 마스터에

버전 (PHPBB3에 대한 인증 공급자의 컨테이너의 정의) https://github.com/phpbb/phpbb/blob/master/phpBB/config/default/container/services_auth.yml

https://github.com/phpbb/phpbb/blob/3.1.x/phpBB/phpbb/auth/provider/provider_interface.php

<?php 
/** 
* 
* This file is part of the phpBB Forum Software package. 
* 
* @copyright (c) phpBB Limited <https://www.phpbb.com> 
* @license GNU General Public License, version 2 (GPL-2.0) 
* 
* For full copyright and license information, please see 
* the docs/CREDITS.txt file. 
* 
*/ 
namespace phpbb\auth\provider; 
/** 
* The interface authentication provider classes have to implement. 
*/ 
interface provider_interface 
{ 
    /** 
    * Checks whether the user is currently identified to the authentication 
    * provider. 
    * Called in acp_board while setting authentication plugins. 
    * Changing to an authentication provider will not be permitted in acp_board 
    * if there is an error. 
    * 
    * @return boolean|string False if the user is identified, otherwise an 
    *       error message, or null if not implemented. 
    */ 
    public function init(); 
    /** 
    * Performs login. 
    * 
    * @param string $username The name of the user being authenticated. 
    * @param string $password The password of the user. 
    * @return array An associative array of the format: 
    *      array(
    *       'status' => status constant 
    *       'error_msg' => string 
    *       'user_row' => array 
    *      ) 
    *     A fourth key of the array may be present: 
    *     'redirect_data' This key is only used when 'status' is 
    *     equal to LOGIN_SUCCESS_LINK_PROFILE and its value is an 
    *     associative array that is turned into GET variables on 
    *     the redirect url. 
    */ 
    public function login($username, $password); 
    /** 
    * Autologin function 
    * 
    * @return array|null containing the user row, empty if no auto login 
    *      should take place, or null if not impletmented. 
    */ 
    public function autologin(); 
    /** 
    * This function is used to output any required fields in the authentication 
    * admin panel. It also defines any required configuration table fields. 
    * 
    * @return array|null Returns null if not implemented or an array of the 
    *      configuration fields of the provider. 
    */ 
    public function acp(); 
    /** 
    * This function updates the template with variables related to the acp 
    * options with whatever configuraton values are passed to it as an array. 
    * It then returns the name of the acp file related to this authentication 
    * provider. 
    * @param array $new_config Contains the new configuration values that 
    *        have been set in acp_board. 
    * @return array|null  Returns null if not implemented or an array with 
    *       the template file name and an array of the vars 
    *       that the template needs that must conform to the 
    *       following example: 
    *       array(
    *        'TEMPLATE_FILE' => string, 
    *        'TEMPLATE_VARS' => array(...), 
    *       ) 
    *       An optional third element may be added to this 
    *       array: 'BLOCK_VAR_NAME'. If this is present, 
    *       then its value should be a string that is used 
    *       to designate the name of the loop used in the 
    *       ACP template file. When this is present, an 
    *       additional key named 'BLOCK_VARS' is required. 
    *       This must be an array containing at least one 
    *       array of variables that will be assigned during 
    *       the loop in the template. An example of this is 
    *       presented below: 
    *       array(
    *        'BLOCK_VAR_NAME' => string, 
    *        'BLOCK_VARS'  => array(
    *         'KEY IS UNIMPORTANT' => array(...), 
    *        ), 
    *        'TEMPLATE_FILE' => string, 
    *        'TEMPLATE_VARS' => array(...), 
    *       ) 
    */ 
    public function get_acp_template($new_config); 
    /** 
    * Returns an array of data necessary to build custom elements on the login 
    * form. 
    * 
    * @return array|null If this function is not implemented on an auth 
    *      provider then it returns null. If it is implemented 
    *      it will return an array of up to four elements of 
    *      which only 'TEMPLATE_FILE'. If 'BLOCK_VAR_NAME' is 
    *      present then 'BLOCK_VARS' must also be present in 
    *      the array. The fourth element 'VARS' is also 
    *      optional. The array, with all four elements present 
    *      looks like the following: 
    *      array(
    *       'TEMPLATE_FILE'  => string, 
    *       'BLOCK_VAR_NAME' => string, 
    *       'BLOCK_VARS'  => array(...), 
    *       'VARS'    => array(...), 
    *      ) 
    */ 
    public function get_login_data(); 
    /** 
    * Performs additional actions during logout. 
    * 
    * @param array $data   An array corresponding to 
    *         \phpbb\session::data 
    * @param boolean $new_session True for a new session, false for no new 
    *         session. 
    */ 
    public function logout($data, $new_session); 
    /** 
    * The session validation function checks whether the user is still logged 
    * into phpBB. 
    * 
    * @param array $user 
    * @return boolean true if the given user is authenticated, false if the 
    *     session should be closed, or null if not implemented. 
    */ 
    public function validate_session($user); 
    /** 
    * Checks to see if $login_link_data contains all information except for the 
    * user_id of an account needed to successfully link an external account to 
    * a forum account. 
    * 
    * @param array $login_link_data Any data needed to link a phpBB account to 
    *        an external account. 
    * @return string|null Returns a string with a language constant if there 
    *      is data missing or null if there is no error. 
    */ 
    public function login_link_has_necessary_data($login_link_data); 
    /** 
    * Links an external account to a phpBB account. 
    * 
    * @param array $link_data Any data needed to link a phpBB account to 
    *        an external account. 
    */ 
    public function link_account(array $link_data); 
    /** 
    * Returns an array of data necessary to build the ucp_auth_link page 
    * 
    * @param int $user_id User ID for whom the data should be retrieved. 
    *      defaults to 0, which is not a valid ID. The method 
    *      should fall back to the current user's ID in this 
    *      case. 
    * @return array|null If this function is not implemented on an auth 
    *      provider then it returns null. If it is implemented 
    *      it will return an array of up to four elements of 
    *      which only 'TEMPLATE_FILE'. If 'BLOCK_VAR_NAME' is 
    *      present then 'BLOCK_VARS' must also be present in 
    *      the array. The fourth element 'VARS' is also 
    *      optional. The array, with all four elements present 
    *      looks like the following: 
    *      array(
    *       'TEMPLATE_FILE'  => string, 
    *       'BLOCK_VAR_NAME' => string, 
    *       'BLOCK_VARS'  => array(...), 
    *       'VARS'    => array(...), 
    *      ) 
    */ 
    public function get_auth_link_data($user_id = 0); 
    /** 
    * Unlinks an external account from a phpBB account. 
    * 
    * @param array $link_data Any data needed to unlink a phpBB account 
    *        from a phpbb account. 
    */ 
    public function unlink_account(array $link_data); 
} 
(아래 그림 참조) :

것은에서 봐 주시기 바랍니다

당신이 젠드 (Zend) 프레임 워크 프로젝트를위한 공급자를 만들기 위해 구현할 수 있습니다.

당신은 공급자가 세션이

https://github.com/phpbb/phpbb/blob/master/phpBB/phpbb/session.php#L560

/* @var $provider_collection \phpbb\auth\provider_collection */ 
    $provider_collection = $phpbb_container->get('auth.provider_collection'); 
    $provider = $provider_collection->get_provider(); 
    $this->data = $provider->autologin(); 

두 프로젝트는, 같은 쿠키를 사용하는지 확인을 만들 때 사용되는 또는 젠드는 또한 phpBB의 쿠키와 세션을 설정하는 방법을 볼 수 있습니다 session_start가 세션 ID를 검색 할 때 사용자가 로그인하는 중입니다.

if ($request->is_set($config['cookie_name'] . '_sid', \phpbb\request\request_interface::COOKIE) || $request->is_set($config['cookie_name'] . '_u', \phpbb\request\request_interface::COOKIE)) 
    { 
     $this->cookie_data['u'] = request_var($config['cookie_name'] . '_u', 0, false, true); 
     $this->cookie_data['k'] = request_var($config['cookie_name'] . '_k', '', false, true); 
     $this->session_id  = request_var($config['cookie_name'] . '_sid', '', false, true); 

     $SID = (defined('NEED_SID')) ? '?sid=' . $this->session_id : '?sid='; 
     $_SID = (defined('NEED_SID')) ? $this->session_id : ''; 

     if (empty($this->session_id)) 
     { 
      $this->session_id = $_SID = request_var('sid', ''); 
      $SID = '?sid=' . $this->session_id; 
      $this->cookie_data = array('u' => 0, 'k' => ''); 
     } 
    } 
    else 
    { 
     $this->session_id = $_SID = request_var('sid', ''); 
     $SID = '?sid=' . $this->session_id; 
    } 

감사합니다.

+0

답변 해 주셔서 감사합니다. 분석을 위해 시간이 좀 걸릴 것입니다.하지만 그렇지 않으면 곧 유효 할 것이기 때문에 현상금을 수여했습니다. 이것은 나에게 나의 문제에 대한 접근의 새로운 장소를 줄 것이고 나를 크게 도울 것이다. – elfwyn

+0

감사합니다!다른 질문이 있거나 나를 명확히 할 필요가 있으면 알려주세요. 나는 적절한 답을 편집 할 것입니다. – vpassapera

+0

새로운 인증 공급자를 만들면 한 번에 하나의 공급자 만 활성화 될 수 있기 때문에 (phpbb acp를 통해 관리 됨) 문서가 말하는 한 phpbb의 기존 인증서를 대체합니다. 그래서 - phpbb와 내 응용 프로그램 모두에서 사용할 새로운 인증 스키마를 작성해야합니까, 아니면 phpbb에 사용 된 기존의 defaut 인증 공급자를 포함/사용하는 방법이 있습니까? 그렇다면 공급자를 검색하기 위해 phpbb_container에 대한 참조를 얻어야합니다. 기존 공급자와 새로운 공급자 사이의 차이점을 알 수는 없습니다. 나는 더 볼 것이다. – elfwyn