OAuth2#

class wikibaseintegrator.wbi_login.OAuth2(consumer_token=None, consumer_secret=None, mediawiki_api_url=None, mediawiki_rest_url=None, token_renew_period=1800, user_agent=None)[source]#

Bases: _Login

This class is used to interact with the OAuth2 API.

Parameters:
  • consumer_token (str | None, default: None) – The consumer token

  • consumer_secret (str | None, default: None) – The consumer secret

  • mediawiki_api_url (str | None, default: None) – The URL to the MediaWiki API (default Wikidata)

  • mediawiki_rest_url (str | None, default: None) – The URL to the MediaWiki REST API (default Wikidata)

  • token_renew_period (int, default: 1800) – Seconds after which a new token should be requested from the Wikidata server

  • user_agent (str | None, default: None) – UA string to use for API requests.

generate_edit_credentials()[source]#

Request an edit token and update the cookie_jar in order to add the session cookie

Return type:

RequestsCookieJar

Returns:

Returns a json with all relevant cookies, aka cookie jar

Can be called in order to retrieve the cookies from an instance of wbi_login.Login

Return type:

RequestsCookieJar

Returns:

Returns a json with all relevant cookies, aka cookie jar

get_edit_token()#

Can be called in order to retrieve the edit token from an instance of wbi_login.Login

Return type:

str | None

Returns:

returns the edit token

get_session()#

Returns the requests.Session object used for the login.

Return type:

Session

Returns:

Object of type requests.Session()

reauthenticate()#

Recover from a session that the server has invalidated (e.g. MediaWiki returning ‘assertuserfailed’/’assertbotfailed’/’notloggedin’ on an otherwise well-formed request, see #902).

Simply asking for a new CSRF token via generate_edit_credentials() cannot resurrect a session the server has already dropped, since that call is itself authenticated by the same (now invalid) session cookies. This default implementation is only adequate for auth methods where generate_edit_credentials() actually re-establishes the underlying credentials (OAuth2, which refreshes its access token first) or where authentication is per-request rather than session-based (OAuth1). Login and Clientlogin override this to redo the full username/password login.

Return type:

None