I'm using DotNetWikiBot to connect to a wiki that's running MediaWiki 1.31.0. It is always running into issues where I get badtoken errors while using the obtained CSRF token, such that the token is seems to be immediately invalid for the next request.
Workaround:
I've realized that the problem goes away if I update the Site.Initialize()
method such that it saves cookies when it's loading the tokens.
As in, change this:
string tokensXmlSrc = GetWebPage(apiPath + ...);
To this:
string tokensXmlSrc = PostDataAndGetResults(apiPath + ..., "", true, true);
And then the tokens aren't invalid anymore.
I should note that in my usage here, my wiki is utilizing a AuthRemoteuserSessionProvider to automatically log in (meaning an action=login API call would return an "Aborted" result), and as such I've byapssed the entire LogIn()
method. But that method doesn't seem to save cookies either.