Php 用新的AuthManager替换AuthPlugin的实现
我的问题是,指南和文档有点复杂和混乱。 它只被设置为“实现一个[ClassName]”,但没有显示一个示例 我的给定代码(a必须重写的旧代码)如下所示:Php 用新的AuthManager替换AuthPlugin的实现,php,authentication,mediawiki,Php,Authentication,Mediawiki,我的问题是,指南和文档有点复杂和混乱。 它只被设置为“实现一个[ClassName]”,但没有显示一个示例 我的给定代码(a必须重写的旧代码)如下所示: class MyAuthPlugin extends AuthPlugin { protected $isAuthenticated = false; function modifyUITemplate( &$template ) { $template->set( 'usedomai
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->从何处?只想强制自动创建)
- 严格的→ 不返回弃权(我应该怎么做?不想进行本地身份验证)
- 如何实例化我的类?使用
docu说,它已被弃用$wgAuth=new MyAuthPLugin()
- 创建一个子类
- 实现
;您可能希望在getAuthenticationRequests
上返回一个新的ACTION\u LOGIN
对象,而不返回任何其他内容(因为您不希望支持通过wiki创建BB用户/更改其密码)PasswordAuthenticationRequest
- 实施
;它与旧的beginprimary认证
大致相同,只是您将凭据作为authenticate
对象数组获取,并使用AuthenticationRequest
获取正确的凭据,然后返回AuthenticationRequest::getRequestByClass($reqs,PasswordAuthenticationRequest::class)
以显示结果(AuthenticationResponse::newXXX
或newPass
-不弃权,因为您不想支持退回到另一种身份验证方法)。如果用户在本地不存在,则自动创建是自动的newFail
- 实现
。这应该在BB数据库中查找用户。(只需始终返回true或false也可能有效——这主要是为了让提供者可以保留名称并防止其他提供者使用。)testUserExists
- 实现
和beginPrimaryAccountCreation
。由于您可能不想支持通过wiki创建BB帐户,只需分别返回accountCreationType
和AuthenticationResponse::newFail
键入\u NONE
- 实施
和ProviderAllowAuthenticationDataChange
。第一个应该在收到密码身份验证请求时返回错误,否则忽略它。第二个应该是空的providerChangeAuthenticationData
$wgAuth=new MyClass()代码>?不需要,只需告诉AuthManager如何实例化它,通过。