37 parent::__construct( $main, $action,
'lg' );
43 return 'apihelp-login-extended-description';
45 return 'apihelp-login-extended-description-nobotpasswords';
54 private function formatMessage( $message ) {
59 $message->useDatabase(
false )->inLanguage(
'en' )->text()
62 return $errorFormatter->formatMessage( $message );
71 private function getErrorCode( $message ) {
73 if ( $message instanceof ApiMessage ) {
74 return $message->getApiCode();
76 return $message->getKey();
93 $this->
getResult()->addValue(
null,
'login', [
94 'result' =>
'Aborted',
95 'reason' => $this->formatMessage(
'api-login-fail-sameorigin' ),
112 if ( !$session->canSetUser() ) {
113 $this->
getResult()->addValue(
null,
'login', [
114 'result' =>
'Aborted',
115 'reason' => $this->formatMessage( [
116 'api-login-fail-badsessionprovider',
117 $session->getProvider()->describe( $this->getErrorFormatter()->getLanguage() ),
129 $token = $session->getToken(
'',
'login' );
130 if ( !$params[
'token'] ) {
131 $authRes =
'NeedToken';
132 } elseif ( $token->wasNew() ) {
135 } elseif ( !$token->match( $params[
'token'] ) ) {
136 $authRes =
'WrongToken';
142 if ( $botLoginData ) {
144 $botLoginData[0], $botLoginData[1], $this->
getRequest()
146 if ( $status->isOK() ) {
147 $session = $status->getValue();
148 $authRes =
'Success';
149 $loginType =
'BotPassword';
151 $status->hasMessage(
'login-throttled' ) ||
152 $status->hasMessage(
'botpasswords-needs-reset' ) ||
153 $status->hasMessage(
'botpasswords-locked' )
156 $message = $status->getMessage();
157 LoggerFactory::getInstance(
'authentication' )->info(
158 'BotPassword login failed: ' . $status->getWikiText(
false,
false,
'en' )
165 if ( $authRes ===
false ) {
167 $reqs = AuthenticationRequest::loadRequestsFromSubmission(
168 $this->authManager->getAuthenticationRequests(
169 AuthManager::ACTION_LOGIN,
173 'username' => $params[
'name'],
174 'password' => $params[
'password'],
175 'domain' => $params[
'domain'],
176 'rememberMe' =>
true,
179 $res = $this->authManager->beginAuthentication( $reqs,
'null:' );
180 switch ( $res->status ) {
181 case AuthenticationResponse::PASS:
183 $this->
addDeprecation(
'apiwarn-deprecation-login-botpw',
'main-account-login' );
185 $this->
addDeprecation(
'apiwarn-deprecation-login-nobotpw',
'main-account-login' );
187 $authRes =
'Success';
188 $loginType =
'AuthManager';
191 case AuthenticationResponse::FAIL:
194 $message = $res->message;
195 LoggerFactory::getInstance(
'authentication' )
196 ->info( __METHOD__ .
': Authentication failed: '
197 . $message->inLanguage(
'en' )->plain() );
201 LoggerFactory::getInstance(
'authentication' )
202 ->info( __METHOD__ .
': Authentication failed due to unsupported response type: '
203 . $res->status, $this->getAuthenticationResponseLogData( $res ) );
204 $authRes =
'Aborted';
209 $result[
'result'] = $authRes;
210 switch ( $authRes ) {
212 $user = $session->getUser();
213 $user->debouncedDBTouch();
217 $this->
getHookRunner()->onUserLoginComplete( $user, $injected_html,
true );
219 $result[
'lguserid'] = $user->getId();
220 $result[
'lgusername'] = $user->getName();
224 $result[
'token'] = $token->toString();
225 $this->
addDeprecation(
'apiwarn-deprecation-login-token',
'action=login&!lgtoken' );
234 $result[
'reason'] = $this->formatMessage( $message );
238 $result[
'reason'] = $this->formatMessage(
240 ?
'api-login-fail-aborted'
241 :
'api-login-fail-aborted-nobotpw'
252 $this->
getResult()->addValue(
null,
'login', $result );
254 LoggerFactory::getInstance(
'authevents' )->info(
'Login attempt', [
256 'successful' => $authRes ===
'Success',
257 'accountType' => $this->identityUtils->getShortUserTypeInternal( $performer ),
258 'loginType' => $loginType,
259 'status' => ( $authRes ===
'Failed' && isset( $message ) ) ? $this->getErrorCode( $message ) : $authRes,
260 'full_message' => isset( $message ) ? $this->formatMessage( $message ) :
'',
269 return new MessageValue(
'apiwarn-deprecation-login-nobotpw' );
293 ParamValidator::PARAM_TYPE =>
'password',
297 ParamValidator::PARAM_TYPE =>
'string',
298 ParamValidator::PARAM_REQUIRED =>
false,
299 ParamValidator::PARAM_SENSITIVE =>
true,
308 'action=login&lgname=user&lgpassword=password&lgtoken=123ABC'
309 =>
'apihelp-login-example-login',
315 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Login';
325 'status' => $response->status,
327 if ( $response->message ) {
328 $ret[
'responseMessage'] = $response->message->inLanguage(
'en' )->plain();
331 'neededRequests' => $response->neededRequests,
332 'createRequest' => $response->createRequest,
333 'linkRequest' => $response->linkRequest,
335 foreach ( $reqs as $k => $v ) {
337 $v = is_array( $v ) ? $v : [ $v ];
338 $reqClasses = array_unique( array_map(
'get_class', $v ) );
340 $ret[$k] = implode(
', ', $reqClasses );
348class_alias( ApiLogin::class,
'ApiLogin' );
if(!defined('MW_SETUP_CALLBACK'))
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()