用新的 AuthManager 替换 AuthPlugin 的实现
Replace implementation of an AuthPlugin with new AuthManager
我的问题,指南和文档有点复杂和混乱。
它只设置了“实现一个[ClassName]”,但没有显示示例。
我给定的代码(必须重写的旧代码)如下:
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 样式?
这个 guide 提出了很多不同的 classes..
userExists() → PrimaryAuthenticationProvider::testUserExists()
authenticate() → PrimaryAuthenticationProvider::beginPrimaryAuthentication + PasswordAuthenticationRequest(我如何将密码传递给进程?)
modifyUITemplate() → 来自 AuthenticationProvider 的 AuthenticationRequests(如何?)+ AuthChangeFormFields 挂钩。
autoCreate() 没有直接替代。 (AuthenticationResponse-> 来自哪里?只想强制自动创建)
strict() → 不要 return 弃权(我应该怎么做?不想进行本地身份验证)
如何实例化我的 class? $wgAuth = new MyAuthPLugin()
docu 说已弃用。
或者在 html-请求中提供用户名、密码(哈希)、sessionID 和密钥时,是否有一种简单的自动登录方法?
您需要:
- 创建一个 AbstractPrimaryAuthenticationProvider 子类
- 实施
getAuthenticationRequests
;您可能想要 return 在 ACTION_LOGIN
上创建一个新的 PasswordAuthenticationRequest
对象,除此之外别无他法(因为您不想支持创建 BB 用户/通过 wiki 更改他们的密码)。
- 实施
beginPrimaryAuthentication
;它将与旧的 authenticate
大致相同,除了您将凭据作为 AuthenticationRequest
对象的数组并使用 AuthenticationRequest::getRequestByClass( $reqs, PasswordAuthenticationRequest::class )
获得正确的凭据,然后 return AuthenticationResponse::newXXX
表示结果(newPass
或 newFail
- 不弃权,因为您不想支持退回到另一种身份验证方法)。如果用户在本地不存在,则自动创建。
- 实施
testUserExists
。这应该在 BB 数据库中查找用户。 (只要一直 return 为 true 或 false 也可能会起作用 - 这主要是为了让提供者可以保留名称并防止其他提供者使用它。)
- 实施
beginPrimaryAccountCreation
和 accountCreationType
。由于您可能不想通过 wiki 支持创建 BB 帐户,因此只需分别 return AuthenticationResponse::newFail
和 TYPE_NONE
。
- 实施
providerAllowsAuthenticationDataChange
和 providerChangeAuthenticationData
。第一个应该 return 在收到密码身份验证请求时出错,否则忽略它。第二个应该是空的。
我的问题,指南和文档有点复杂和混乱。 它只设置了“实现一个[ClassName]”,但没有显示示例。
我给定的代码(必须重写的旧代码)如下:
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 样式? 这个 guide 提出了很多不同的 classes..
userExists() → PrimaryAuthenticationProvider::testUserExists()
authenticate() → PrimaryAuthenticationProvider::beginPrimaryAuthentication + PasswordAuthenticationRequest(我如何将密码传递给进程?)
modifyUITemplate() → 来自 AuthenticationProvider 的 AuthenticationRequests(如何?)+ AuthChangeFormFields 挂钩。
autoCreate() 没有直接替代。 (AuthenticationResponse-> 来自哪里?只想强制自动创建)
strict() → 不要 return 弃权(我应该怎么做?不想进行本地身份验证)
如何实例化我的 class?
$wgAuth = new MyAuthPLugin()
docu 说已弃用。
或者在 html-请求中提供用户名、密码(哈希)、sessionID 和密钥时,是否有一种简单的自动登录方法?
您需要:
- 创建一个 AbstractPrimaryAuthenticationProvider 子类
- 实施
getAuthenticationRequests
;您可能想要 return 在ACTION_LOGIN
上创建一个新的PasswordAuthenticationRequest
对象,除此之外别无他法(因为您不想支持创建 BB 用户/通过 wiki 更改他们的密码)。 - 实施
beginPrimaryAuthentication
;它将与旧的authenticate
大致相同,除了您将凭据作为AuthenticationRequest
对象的数组并使用AuthenticationRequest::getRequestByClass( $reqs, PasswordAuthenticationRequest::class )
获得正确的凭据,然后 returnAuthenticationResponse::newXXX
表示结果(newPass
或newFail
- 不弃权,因为您不想支持退回到另一种身份验证方法)。如果用户在本地不存在,则自动创建。 - 实施
testUserExists
。这应该在 BB 数据库中查找用户。 (只要一直 return 为 true 或 false 也可能会起作用 - 这主要是为了让提供者可以保留名称并防止其他提供者使用它。) - 实施
beginPrimaryAccountCreation
和accountCreationType
。由于您可能不想通过 wiki 支持创建 BB 帐户,因此只需分别 returnAuthenticationResponse::newFail
和TYPE_NONE
。 - 实施
providerAllowsAuthenticationDataChange
和providerChangeAuthenticationData
。第一个应该 return 在收到密码身份验证请求时出错,否则忽略它。第二个应该是空的。