Page MenuHomePhabricator

ApiQueryTokens should allow retrieval of all types of available tokens
Closed, ResolvedPublicFeature

Description

Currently, all available tokens can be fetched by calling (in series):

  • action=paraminfo&modules=query+tokens (to get list of token types – which can differ between wikis based on extensions installed)
  • action=query&meta=tokens

From the perspective of a bot library, it would be great if this could be done in one step – that is, the latter could provide an option to fetch all types of tokens without having to first fetch the list of token types.

Event Timeline

Change 733948 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/core@master] Allow retrieval of tokens of all available types in one request

https://gerrit.wikimedia.org/r/733948

Change 734326 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/core@master] Allow retrieval of tokens of all available types in one request

https://gerrit.wikimedia.org/r/734326

Change 734326 abandoned by SD0001:

[mediawiki/core@master] Allow retrieval of tokens of all available types in one request

Reason:

Dupe of 733948. Created from git review accident

https://gerrit.wikimedia.org/r/734326

Change 733948 merged by jenkins-bot:

[mediawiki/core@master] Allow retrieval of tokens of all available types in one request

https://gerrit.wikimedia.org/r/733948

@SD0001 I'm curious, what is the use case for a framework to unconditionally fetch all available types? Why would a bot want this feature in a framework?

Bot frameworks generally build token caches to allow the user to write API calls like: api.post({ ...., token: tokenCache.get('csrf') }), so they don't have to fetch a token before each request. It's easier to refresh this cache in one request rather than go through the more complicated flow mentioned in OP.

Also, when a request fails due to an expired token, a good framework would handle it this way:

  1. Original API request (fails with badtoken)
  2. Fetch type of token needed for this action (ApiParamInfo)
  3. Fetch the token
  4. Retry original request with new token

That's 4 API requests in series, which is slow – especially if this is an action done in a webservice with the end-user waiting. To speed things things up a bit, we could parallelize 2 and 3 – but this only works correctly if there's a way to fetch tokens of all types.

SD0001 claimed this task.