API:Login/fr

Vous devrez probablement faire en sorte d'authentifier votre application ou votre client en utilisant un service d'API MédiaWiki. As of MediaWiki 1.27, there are two API actions used to authenticate:  and.

Bots and other non-interactive applications should generally use owner-only OAuth consumers when available to authenticate as it is more secure, however bot passwords can be used with the  action as described on this page.

Interactive applications such as custom editors or patrolling applications that provide a service without intending to fully replace the website should generally also use OAuth for authenticating the tool, as it is easier and more secure, however the  action can be used if that is unavailable.

Interactive applications such as mobile apps that aim to completely replace access to the web-based user interface should use the  action to authenticate.

Quand m'authentifier ?
Votre client doit s'identifier si:


 * il doit obtenir des information ou effectuer des actions qui nécessitent des droits d'accès particuliers
 * il fait des requêtes de grandes tailles, et serait inefficace sans bénéficier des limites plus hautes qu'ont les comptes avec certains droits

Sur les wikis qui authorisent les modifications anonymes, il est possible d'éditer par l'API sans s'authentifier, mais il est fortement recommandé de le faire tout de même. Sur les wikis privés, vous devez vous identifier pour utiliser l'API, quelle que soit la fonctionnalité

Si votre client est écrit en JavaScript et tourne dans le navigateur, il bénéficie des droits associés à l'utilisateur pour ce navigateur. Dans ce cas, il n'est pas nécessaire de s'identifier en utilisant l'API dédiée -- vous devez seulement vous assurez que l'utilisateur est identifié sur l'interface web.

If your client is using OAuth or a similar mechanism, it will not need to explicitly log in as all OAuth requests are already authenticated.

Comptes utilisateurs dédiés à une application
Plutôt que d'avoir votre application identifiée comme vous même, vous pourriez vouloir lui créer un compte utilisateur. Ceci est particulièrement important si votre application:


 * effectuera des modifications automatisées ou une autre sorte d'opérations de masses.
 * fait effectuer des requêtes de grandes tailles ou qui requièrent beaucoup de puissance de calcul

Avec un compte utilisateur dédié, les changement effectués par votre appli peuvent être facilement trouvés, et des droits spéciaux (généralement ceux d'un groupe "bot") pourront lui être attribués. Certains wiki ont une politique concernant les modifications de robots, et/ou une procédure pour gérer les requêtes des utilisateurs du groupe "bot".

How to check if you're logged in
The login mechanism typically uses cookies to track the logged-in status of a session. Clients should check directly if they are logged in, rather than attempting to determine the status by examining the cookies or by blindly logging in whether or not it is required.

The recommended way to ensure that requests are logged in is to use the assert=user parameter accepted on all API calls. When this parameter is provided and the user is not logged in, an assertuserfailed error will be returned.

To directly check which user (if any) you are currently logged in as, use the query module.

Comment s'identifier
In MediaWiki versions before 1.27, only the  action is available and should be used by all clients needing to login. As of 1.27, the  action should only be used in combination with bot passwords, and   should be used by interactive applications.

Note that logging in and remaining logged in requires correct HTTP cookie handling by your client on all requests. Typically your framework or HTTP request library will handle this for you.

The action
To successfully log in, a login token must first be retrieved. This token should be fetched using a query in MediaWiki 1.27 and later. For older versions, a POST to the  action is required instead.

Other fields might be included in the response, however these are deprecated and should be ignored if present.

Once the token has been fetched, the login may proceed.

Other fields might be included in the response, however these are deprecated and should be ignored if present.

The result field in the output indicates whether the login was successful. Non-successful results include:


 * NeedToken if the lgtoken parameter was not provided or no session was active (e.g. your cookie handling is broken).
 * WrongToken if the supplied token was not a valid token.
 * Failed (since 1.27) if the login failed. A reason field will exist in the response containing and explanation of the failure.
 * Aborted (since 1.27) if the login using the main account password (rather than a bot password) cannot proceed because user interaction is required. The  action should be used instead.
 * NoName (before 1.27) if no lgname was provided.
 * Illegal (before 1.27) if the lgname is not a valid user name.
 * NotExists (before 1.27) if supplied user does not exist.
 * EmptyPass (before 1.27) if the supplied password is empty.
 * WrongPass or WrongPluginPass (before 1.27) if the password is incorrect.
 * CreateBlocked (before 1.27) if auto-creation of the account is required but is not possible.
 * Throttled (before 1.27) if login attempts from your IP have been throttled.
 * Blocked (before 1.27) if the user being logged in to is blocked and blocks prevent login on the wiki.
 * Aborted (before 1.27) if the login was aborted by an extension without further detail. A reason field may be present.

The action
This action implements an interactive login process, which might include CAPTCHAs, interactions with third-party authentication services, two-factor authentication, and more. As such, the specific fields required may vary depending on the configuration of the wiki. A description of the fields needed should be fetched from the query.

On a wiki without any special authentication extensions, the fields needed might include username, password , and optionally rememberMe , so the login request would look something like this:

On the other hand, a wiki with a CAPTCHA extension, an extension for authentication using OpenID Connect, and a two-factor authentication extension might have a more complicated authentication process.

The client would be expected to redirect the user's browser to the provided redirecttarget. The OpenID provider would authenticate, and redirect to Special:OpenIDConnectReturn on the wiki, which would validate the OpenID response and then redirect to the loginreturnurl provided in the first POST to the API with the code and state parameters added. The client gets control of the process back at this point and makes its next API request.

Now the client needs to ask the user to check their two-factor authentication app for the current code, and submit that back to the server to continue the authentication process.

The authentication process has finally succeeded.

If at any point authentication fails, a response with status FAIL will be returned, along with a message to display to the user.

In certain cases it's possible to receive a RESTART response, for example if the OpenID Connect extension had no mapping for the OpenID account to any local user. In this case the client might restart the login process from the beginning or might switch to account creation, in either case passing the loginpreservestate or createpreservestate parameter to preserve some state.