38 parent::__construct( $main, $action,
'lg' );
42 if ( $this->
getConfig()->
get(
'EnableBotPasswords' ) ) {
43 return 'apihelp-login-extended-description';
45 return 'apihelp-login-extended-description-nobotpasswords';
59 $message->useDatabase(
false )->inLanguage(
'en' )->text()
62 return $errorFormatter->formatMessage( $message );
79 $this->
getResult()->addValue(
null,
'login', [
80 'result' =>
'Aborted',
81 'reason' => $this->
formatMessage(
'api-login-fail-sameorigin' ),
94 $session = MediaWiki\Session\SessionManager::getGlobalSession();
98 if ( !$session->canSetUser() ) {
99 $this->
getResult()->addValue(
null,
'login', [
100 'result' =>
'Aborted',
102 'api-login-fail-badsessionprovider',
103 $session->getProvider()->describe( $this->getErrorFormatter()->getLanguage() ),
114 $token = $session->getToken(
'',
'login' );
115 if ( !$params[
'token'] ) {
116 $authRes =
'NeedToken';
117 } elseif ( $token->wasNew() ) {
119 $message = ApiMessage::create(
'authpage-cannot-login-continue',
'sessionlost' );
120 } elseif ( !$token->match( $params[
'token'] ) ) {
121 $authRes =
'WrongToken';
126 $authRes ===
false && $this->
getConfig()->
get(
'EnableBotPasswords' ) &&
127 ( $botLoginData = BotPassword::canonicalizeLoginData( $params[
'name'], $params[
'password'] ) )
129 $status = BotPassword::login(
130 $botLoginData[0], $botLoginData[1], $this->
getRequest()
132 if ( $status->isOK() ) {
133 $session = $status->getValue();
134 $authRes =
'Success';
135 $loginType =
'BotPassword';
137 $status->hasMessage(
'login-throttled' ) ||
138 $status->hasMessage(
'botpasswords-needs-reset' ) ||
139 $status->hasMessage(
'botpasswords-locked' )
142 $message = $status->getMessage();
143 LoggerFactory::getInstance(
'authentication' )->info(
144 'BotPassword login failed: ' . $status->getWikiText(
false,
false,
'en' )
150 if ( $authRes ===
false ) {
152 $manager = MediaWikiServices::getInstance()->getAuthManager();
153 $reqs = AuthenticationRequest::loadRequestsFromSubmission(
154 $manager->getAuthenticationRequests( AuthManager::ACTION_LOGIN, $this->getUser() ),
156 'username' => $params[
'name'],
157 'password' => $params[
'password'],
158 'domain' => $params[
'domain'],
159 'rememberMe' =>
true,
162 $res = $manager->beginAuthentication( $reqs,
'null:' );
163 switch (
$res->status ) {
164 case AuthenticationResponse::PASS:
165 if ( $this->
getConfig()->
get(
'EnableBotPasswords' ) ) {
166 $this->
addDeprecation(
'apiwarn-deprecation-login-botpw',
'main-account-login' );
168 $this->
addDeprecation(
'apiwarn-deprecation-login-nobotpw',
'main-account-login' );
170 $authRes =
'Success';
171 $loginType =
'AuthManager';
174 case AuthenticationResponse::FAIL:
177 $message =
$res->message;
178 \MediaWiki\Logger\LoggerFactory::getInstance(
'authentication' )
179 ->info( __METHOD__ .
': Authentication failed: '
180 . $message->inLanguage(
'en' )->plain() );
184 \MediaWiki\Logger\LoggerFactory::getInstance(
'authentication' )
185 ->info( __METHOD__ .
': Authentication failed due to unsupported response type: '
186 .
$res->status, $this->getAuthenticationResponseLogData(
$res ) );
187 $authRes =
'Aborted';
192 $result[
'result'] = $authRes;
193 switch ( $authRes ) {
195 $user = $session->getUser();
201 $this->
getHookRunner()->onUserLoginComplete( $user, $injected_html,
true );
203 $result[
'lguserid'] = (int)$user->getId();
204 $result[
'lgusername'] = $user->getName();
208 $result[
'token'] = $token->toString();
209 $this->
addDeprecation(
'apiwarn-deprecation-login-token',
'action=login&!lgtoken' );
221 $this->
getConfig()->
get(
'EnableBotPasswords' )
222 ?
'api-login-fail-aborted'
223 :
'api-login-fail-aborted-nobotpw'
234 $this->
getResult()->addValue(
null,
'login', $result );
236 LoggerFactory::getInstance(
'authevents' )->info(
'Login attempt', [
238 'successful' => $authRes ===
'Success',
239 'loginType' => $loginType,
240 'status' => $authRes,
245 return !$this->
getConfig()->get(
'EnableBotPasswords' );
274 'action=login&lgname=user&lgpassword=password&lgtoken=123ABC'
275 =>
'apihelp-login-example-login',
280 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Login';
290 'status' => $response->status,
292 if ( $response->message ) {
293 $ret[
'responseMessage'] = $response->message->inLanguage(
'en' )->plain();
296 'neededRequests' => $response->neededRequests,
297 'createRequest' => $response->createRequest,
298 'linkRequest' => $response->linkRequest,
300 foreach ( $reqs as $k => $v ) {
302 $v = is_array( $v ) ? $v : [ $v ];
303 $reqClasses = array_unique( array_map(
'get_class', $v ) );
305 $ret[$k] = implode(
', ', $reqClasses );
This abstract class implements many basic API functions, and is the base of all API classes.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
getErrorFormatter()
Get the error formatter Stable to override.
requirePostedParameters( $params, $prefix='prefix')
Die if any of the specified parameters were found in the query part of the URL rather than the post b...
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
Unit to authenticate log-in attempts to the current wiki.
formatMessage( $message)
Format a message for the response.
getHelpUrls()
Return links to more detailed help pages about the module.
getExtendedDescription()
Return the extended help text message.
isDeprecated()
Indicates whether this module is deprecated.
__construct(ApiMain $main, $action)
isReadMode()
Indicates whether this module requires read rights Stable to override.
mustBePosted()
Indicates whether this module must be called with a POST request Stable to override.
execute()
Executes the log-in attempt using the parameters passed.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getAuthenticationResponseLogData(AuthenticationResponse $response)
Turns an AuthenticationResponse into a hash suitable for passing to Logger.
getExamplesMessages()
Returns usage examples for this module.
This is the main API class, used for both external and internal processing.
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...