45 parent::__construct( $main, $action,
'lg' );
46 $this->authManager = $authManager;
47 $this->identityUtils = $identityUtils;
53 return 'apihelp-login-extended-description';
55 return 'apihelp-login-extended-description-nobotpasswords';
64 private function formatMessage( $message ) {
69 $message->useDatabase(
false )->inLanguage(
'en' )->text()
72 return $errorFormatter->formatMessage( $message );
81 private function getErrorCode( $message ) {
83 if ( $message instanceof ApiMessage ) {
84 return $message->getApiCode();
86 return $message->getKey();
103 $this->
getResult()->addValue(
null,
'login', [
104 'result' =>
'Aborted',
105 'reason' => $this->formatMessage(
'api-login-fail-sameorigin' ),
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' );
140 if ( !$params[
'token'] ) {
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,
183 'username' => $params[
'name'],
184 'password' => $params[
'password'],
185 'domain' => $params[
'domain'],
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();
223 $user->debouncedDBTouch();
227 $this->
getHookRunner()->onUserLoginComplete( $user, $injected_html,
true );
229 $result[
'lguserid'] = $user->getId();
230 $result[
'lgusername'] = $user->getName();
234 $result[
'token'] = $token->toString();
235 $this->
addDeprecation(
'apiwarn-deprecation-login-token',
'action=login&!lgtoken' );
244 $result[
'reason'] = $this->formatMessage( $message );
248 $result[
'reason'] = $this->formatMessage(
250 ?
'api-login-fail-aborted'
251 :
'api-login-fail-aborted-nobotpw'
262 $this->
getResult()->addValue(
null,
'login', $result );
264 LoggerFactory::getInstance(
'authevents' )->info(
'Login attempt', [
266 'successful' => $authRes ===
'Success',
267 'accountType' => $this->identityUtils->getShortUserTypeInternal( $performer ),
268 'loginType' => $loginType,
269 'status' => ( $authRes ===
'Failed' && isset( $message ) ) ? $this->getErrorCode( $message ) : $authRes,
270 'full_message' => isset( $message ) ? $this->formatMessage( $message ) :
'',
300 ParamValidator::PARAM_TYPE =>
'password',
304 ParamValidator::PARAM_TYPE =>
'string',
305 ParamValidator::PARAM_REQUIRED =>
false,
306 ParamValidator::PARAM_SENSITIVE =>
true,
315 'action=login&lgname=user&lgpassword=password&lgtoken=123ABC'
316 =>
'apihelp-login-example-login',
322 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Login';
332 'status' => $response->status,
334 if ( $response->message ) {
335 $ret[
'responseMessage'] = $response->message->inLanguage(
'en' )->plain();
338 'neededRequests' => $response->neededRequests,
339 'createRequest' => $response->createRequest,
340 'linkRequest' => $response->linkRequest,
342 foreach ( $reqs as $k => $v ) {
344 $v = is_array( $v ) ? $v : [ $v ];
345 $reqClasses = array_unique( array_map(
'get_class', $v ) );
347 $ret[$k] = implode(
', ', $reqClasses );
355class_alias( ApiLogin::class,
'ApiLogin' );
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()