Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用新的AuthManager替换AuthPlugin的实现_Php_Authentication_Mediawiki - Fatal编程技术网

Php 用新的AuthManager替换AuthPlugin的实现

Php 用新的AuthManager替换AuthPlugin的实现,php,authentication,mediawiki,Php,Authentication,Mediawiki,我的问题是,指南和文档有点复杂和混乱。 它只被设置为“实现一个[ClassName]”,但没有显示一个示例 我的给定代码(a必须重写的旧代码)如下所示: class MyAuthPlugin extends AuthPlugin { protected $isAuthenticated = false; function modifyUITemplate( &$template ) { $template->set( 'usedomai

我的问题是,指南和文档有点复杂和混乱。 它只被设置为“实现一个[ClassName]”,但没有显示一个示例

我的给定代码(a必须重写的旧代码)如下所示:

class MyAuthPlugin extends AuthPlugin {

  protected $isAuthenticated = false;
           
  function modifyUITemplate( &$template ) {
      $template->set( 'usedomain', false );
      $template->set( 'useemail',  false ); 
      $template->set( 'canreset',  false );
      $template->set( 'create',    false );
  }


  function autoCreate() {
      return true;
  }

  function userExists( $username ) {  
      return true;  //already handled in ohter function
  }

  function strict() {   
      return true;  
  }

  /* Being called twice:
   * Login->attemptAutoCreate() (SpecialUserLogin.php) (only for new)
   * User->checkPassword() (User.php) external PW-authentication.  
   */   
  function authenticate( $username, $password ) {
      global $BBredirect, $BBconnection, $wgRequest;

      if($this->isAuthenticated) return true;
    
      $BBConnection['Parameters']  = 'cmd=authenticate&sessionId='.$wgRequest->getVal('sessionId');
    
      $myRequest = new SimpleHttpRequest($BBConnection);
      $responseGET = $myRequest->doRequest(SimpleHttpRequest::HTTP_GET);
      echo ($responseGET[Content]);
    
      $auth = simplexml_load_string($responseGET[Content]);

      if($auth->response->authentication ==  'false') {
          return false;
      }
        
      if($auth->response->authentication == 'ok') {
          $this->isAuthenticated = true;
      }
      return $this->isAuthenticated;
  }

  function isAuthenticated() {
      return $this->isAuthenticated;
  }

}
如何将此代码转换为新的AuthManager样式? 这说明有很多不同的课程

  • userExists()→ PrimaryAuthenticationProvider::testUserExists()

  • 验证()→ PrimaryAuthenticationProvider::beginPrimaryAuthentication+PasswordAuthenticationRequest(如何将密码传递给进程?)

  • modifyUITemplate()→ 来自AuthenticationProvider的AuthenticationRequests(如何?)+AuthChangeFormFields钩子

  • autoCreate()没有直接替换。(AuthenticationResponse->从何处?只想强制自动创建)

  • 严格的→ 不返回弃权(我应该怎么做?不想进行本地身份验证)

  • 如何实例化我的类?使用
    $wgAuth=new MyAuthPLugin()
    docu说,它已被弃用

或者,当html请求中提供用户名、密码(哈希)、会话ID和secretkey时,是否有一种简单的自动登录方法?

您需要:

  • 创建一个子类
  • 实现
    getAuthenticationRequests
    ;您可能希望在
    ACTION\u LOGIN
    上返回一个新的
    PasswordAuthenticationRequest
    对象,而不返回任何其他内容(因为您不希望支持通过wiki创建BB用户/更改其密码)
  • 实施
    beginprimary认证
    ;它与旧的
    authenticate
    大致相同,只是您将凭据作为
    AuthenticationRequest
    对象数组获取,并使用
    AuthenticationRequest::getRequestByClass($reqs,PasswordAuthenticationRequest::class)
    获取正确的凭据,然后返回
    AuthenticationResponse::newXXX
    以显示结果(
    newPass
    newFail
    -不弃权,因为您不想支持退回到另一种身份验证方法)。如果用户在本地不存在,则自动创建是自动的
  • 实现
    testUserExists
    。这应该在BB数据库中查找用户。(只需始终返回true或false也可能有效——这主要是为了让提供者可以保留名称并防止其他提供者使用。)
  • 实现
    beginPrimaryAccountCreation
    accountCreationType
    。由于您可能不想支持通过wiki创建BB帐户,只需分别返回
    AuthenticationResponse::newFail
    键入\u NONE
  • 实施
    ProviderAllowAuthenticationDataChange
    providerChangeAuthenticationData
    。第一个应该在收到密码身份验证请求时返回错误,否则忽略它。第二个应该是空的

谢谢,这让我有了一个开始。我必须如何实例化这个类?是否替换了
$wgAuth=new MyClass()?不需要,只需告诉AuthManager如何实例化它,通过。