60 parent::__construct( $main, $action,
'lg' );
61 $this->authManager = $authManager;
62 $this->identityUtils = $identityUtils;
67 return 'apihelp-login-extended-description';
69 return 'apihelp-login-extended-description-nobotpasswords';
78 private function formatMessage( $message ) {
83 $message->useDatabase(
false )->inLanguage(
'en' )->text()
86 return $errorFormatter->formatMessage( $message );
103 $this->
getResult()->addValue(
null,
'login', [
104 'result' =>
'Aborted',
105 'reason' => $this->formatMessage(
'api-login-fail-sameorigin' ),
118 $session = SessionManager::getGlobalSession();
122 if ( !$session->canSetUser() ) {
123 $this->
getResult()->addValue(
null,
'login', [
124 'result' =>
'Aborted',
125 'reason' => $this->formatMessage( [
126 'api-login-fail-badsessionprovider',
127 $session->getProvider()->describe( $this->getErrorFormatter()->getLanguage() ),
139 $token = $session->getToken(
'',
'login' );
141 $authRes =
'NeedToken';
142 } elseif ( $token->wasNew() ) {
145 } elseif ( !$token->match(
$params[
'token'] ) ) {
146 $authRes =
'WrongToken';
152 if ( $botLoginData ) {
154 $botLoginData[0], $botLoginData[1], $this->
getRequest()
156 if ( $status->isOK() ) {
157 $session = $status->getValue();
158 $authRes =
'Success';
159 $loginType =
'BotPassword';
161 $status->hasMessage(
'login-throttled' ) ||
162 $status->hasMessage(
'botpasswords-needs-reset' ) ||
163 $status->hasMessage(
'botpasswords-locked' )
166 $message = $status->getMessage();
167 LoggerFactory::getInstance(
'authentication' )->info(
168 'BotPassword login failed: ' . $status->getWikiText(
false,
false,
'en' )
175 if ( $authRes ===
false ) {
177 $reqs = AuthenticationRequest::loadRequestsFromSubmission(
178 $this->authManager->getAuthenticationRequests(
179 AuthManager::ACTION_LOGIN,
184 'password' =>
$params[
'password'],
186 'rememberMe' =>
true,
189 $res = $this->authManager->beginAuthentication( $reqs,
'null:' );
190 switch ( $res->status ) {
191 case AuthenticationResponse::PASS:
193 $this->
addDeprecation(
'apiwarn-deprecation-login-botpw',
'main-account-login' );
195 $this->
addDeprecation(
'apiwarn-deprecation-login-nobotpw',
'main-account-login' );
197 $authRes =
'Success';
198 $loginType =
'AuthManager';
201 case AuthenticationResponse::FAIL:
204 $message = $res->message;
205 LoggerFactory::getInstance(
'authentication' )
206 ->info( __METHOD__ .
': Authentication failed: '
207 . $message->inLanguage(
'en' )->plain() );
211 LoggerFactory::getInstance(
'authentication' )
212 ->info( __METHOD__ .
': Authentication failed due to unsupported response type: '
213 . $res->status, $this->getAuthenticationResponseLogData( $res ) );
214 $authRes =
'Aborted';
219 $result[
'result'] = $authRes;
220 switch ( $authRes ) {
222 $user = $session->getUser();
226 $this->
getHookRunner()->onUserLoginComplete( $user, $injected_html,
true );
228 $result[
'lguserid'] = $user->getId();
229 $result[
'lgusername'] = $user->getName();
233 $result[
'token'] = $token->toString();
234 $this->
addDeprecation(
'apiwarn-deprecation-login-token',
'action=login&!lgtoken' );
243 $result[
'reason'] = $this->formatMessage( $message );
247 $result[
'reason'] = $this->formatMessage(
249 ?
'api-login-fail-aborted'
250 :
'api-login-fail-aborted-nobotpw'
261 $this->
getResult()->addValue(
null,
'login', $result );
263 LoggerFactory::getInstance(
'authevents' )->info(
'Login attempt', [
265 'successful' => $authRes ===
'Success',
266 'accountType' => $this->identityUtils->getShortUserTypeInternal( $performer ),
267 'loginType' => $loginType,
268 'status' => $authRes,
293 ParamValidator::PARAM_TYPE =>
'password',
297 ParamValidator::PARAM_TYPE =>
'string',
298 ParamValidator::PARAM_REQUIRED =>
false,
299 ParamValidator::PARAM_SENSITIVE =>
true,
307 'action=login&lgname=user&lgpassword=password&lgtoken=123ABC'
308 =>
'apihelp-login-example-login',
313 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Login';
323 'status' => $response->status,
325 if ( $response->message ) {
326 $ret[
'responseMessage'] = $response->message->inLanguage(
'en' )->plain();
329 'neededRequests' => $response->neededRequests,
330 'createRequest' => $response->createRequest,
331 'linkRequest' => $response->linkRequest,
333 foreach ( $reqs as $k => $v ) {
335 $v = is_array( $v ) ? $v : [ $v ];
336 $reqClasses = array_unique( array_map(
'get_class', $v ) );
338 $ret[$k] = implode(
', ', $reqClasses );
346class_alias( ApiLogin::class,
'ApiLogin' );
array $params
The job parameters.
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const EnableBotPasswords
Name constant for the EnableBotPasswords setting, for use with Config::get()