If 'token' is a magic parameter that ApiMain understands, ApiBase should add it to getAllowedParams() and getParamDescription()
Version: unspecified
Severity: enhancement
If 'token' is a magic parameter that ApiMain understands, ApiBase should add it to getAllowedParams() and getParamDescription()
Version: unspecified
Severity: enhancement
| Status | Subtype | Assigned | Task | ||
|---|---|---|---|---|---|
| Open | Feature | None | T40891 MediaWiki API 2.0 (tracking) | ||
| Resolved | None | T37993 gettoken should go die in a fire | |||
| Resolved | Anomie | T38078 ApiTokens should be a query module | |||
| Resolved | Anomie | T47199 API token handling needs to be less special-cased and hard-coded |
We really need to overhaul how tokens work in general. It should be simpler for a module to add a token requirement, and all tokens should be gettable from action=tokens.
Brainstorming:
Right now, it seems a module has to return true for needsToken() and non-false for getTokenSalt() and include a 'token' parameter in getAllowedParams() and either add itself somewhere in the middle of ApiTokens or hook ApiTokensGetTokenTypes. And maybe also add itself to ApiQueryInfo or hook APIQueryInfoTokens, and maybe ApiQueryRevisions or hook APIQueryRevisionsTokens, and maybe ApiQueryUsers or hook APIQueryUsersTokens, and maybe ApiQueryRecentChanges or hook APIQueryRecentChangesTokens. And some modules may just be doing it on their own.
Right now, it's using static functions all over the place to get the tokens. Which is nice in that it means classes don't have to be instantiated, but makes it hard to handle the next bullet.
Right now, not really handled at all. It looks like the rollback token you can only get through prop=revisions, and the userrights token you can only get through list=users, and if there's anything in an extension it probably either implements its own "gettoken"-style parameter (see bug 35993) or has its own query module which is the only way to get its token (like rollback or userrights).
This also solves the problem where you don't necessarily know which "type" is needed for any particular module, although that could also be solved with better parameter documentation.
The annoying part is making sure we don't break any of the ways a module does tokens now.
Under ideal circumstances I'd recommend this:
This should help simplify things. :)
(In reply to comment #2)
Under ideal circumstances I'd recommend this:
- drop all uses of token salt -- use the same token for all things in the
session
- return the token in the login response along with the session key
- have a single method for fetching the token (if using saved login cookies,
for instance)
This should help simplify things. :)
I'd agree with all except removing the salt. I'd prefer that the editing token not also work for creating accounts and deleting articles, but unfortunately I don't have too much of a reason because the reasons for giving per-request tokens in the browser interface don't apply to the API.