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:
_LoginThis class is used to interact with the OAuth1 API.
- Parameters:
consumer_token (
str|None, default:None) – The consumer tokenconsumer_secret (
str|None, default:None) – The consumer secretaccess_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 handshakemediawiki_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 serveruser_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.
- generate_edit_credentials()#
Request an edit token and update the cookie_jar in order to add the session cookie
- Return type:
- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_cookie()#
Can be called in order to retrieve the cookies from an instance of wbi_login.Login
- Return type:
- 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
- get_session()#
Returns the requests.Session object used for the login.
- Return type:
- 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: