OAuth1#

class wikibaseintegrator.wbi_login.OAuth1(consumer_token=None, consumer_secret=None, access_token=None, access_secret=None, callback_url='oob', mediawiki_api_url=None, mediawiki_index_url=None, token_renew_period=1800, user_agent=None)[source]#

Bases: _Login

This class is used to interact with the OAuth1 API.

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

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

  • access_token (str | None, default: None) – The access token (optional )

  • access_secret (str | None, default: None) – The access secret (optional)

  • callback_url (str, default: 'oob') – The callback URL used to finalize the handshake

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

  • mediawiki_index_url (str | None, default: None) – The URL to the MediaWiki index (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.

continue_oauth(oauth_callback_data=None)[source]#

Continuation of OAuth procedure. Method must be explicitly called in order to complete OAuth. This allows external entities, e.g. websites, to provide tokens through callback URLs directly.

Parameters:

oauth_callback_data (str | None, default: None) – The callback URL received to a Web app

Return type:

None

Returns:

generate_edit_credentials()#

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