pytwitcherapi.session.OAuthSession¶
-
class
pytwitcherapi.session.
OAuthSession
[source]¶ Bases:
requests_oauthlib.oauth2_session.OAuth2Session
Session with oauth2 support.
You can still use http requests.
Methods
__init__
()Initialize a new oauth session authorization_url
(url[, state])Form an authorization URL. close
()Closes all adapters and as such the session delete
(url, **kwargs)Sends a DELETE request. fetch_token
(token_url[, code, ...])Generic method for fetching an access token from the token endpoint. get
(url, **kwargs)Sends a GET request. get_adapter
(url)Returns the appropriate connection adapter for the given URL. get_auth_url
()Return the url for the user to authorize PyTwitcher get_redirect_target
(resp)Receives a Response. head
(url, **kwargs)Sends a HEAD request. merge_environment_settings
(url, proxies, ...)Check the environment and merge it with some settings. mount
(prefix, adapter)Registers a connection adapter to a prefix. new_state
()Generates a state string to be used in authorizations. options
(url, **kwargs)Sends a OPTIONS request. patch
(url[, data])Sends a PATCH request. post
(url[, data, json])Sends a POST request. prepare_request
(request)Constructs a PreparedRequest
for transmission and returns it.put
(url[, data])Sends a PUT request. rebuild_auth
(prepared_request, response)When being redirected we may want to strip authentication from the request to avoid leaking credentials. rebuild_method
(prepared_request, response)When being redirected we may want to change the method of the request based on certain specs or browser behavior. rebuild_proxies
(prepared_request, proxies)This method re-evaluates the proxy configuration by considering the environment variables. refresh_token
(token_url[, refresh_token, ...])Fetch a new access token using a refresh token. register_compliance_hook
(hook_type, hook)Register a hook for request/response tweaking. request
(method, url, **kwargs)Constructs a requests.Request
, prepares it and sends it.resolve_redirects
(resp, req[, stream, ...])Receives a Response. send
(request, **kwargs)Send a given PreparedRequest. shutdown_login_server
()Shutdown the login server and thread start_login_server
()Start a server that will get a request from a user logging in. token_from_fragment
(authorization_response)Parse token from the URI fragment, used by MobileApplicationClients. Attributes
access_token
authorized
Boolean that indicates whether this session has an OAuth token or not. client_id
token
-
login_server
= None¶ The server that handles the login redirect
-
login_thread
= None¶ The thread that serves the login server
-
request
(method, url, **kwargs)[source]¶ Constructs a
requests.Request
, prepares it and sends it. Raises HTTPErrors by default.Parameters: - method (
str
) – method for the newRequest
object. - url (
str
) – URL for the newRequest
object. - kwargs – keyword arguments of
requests.Session.request()
Returns: a resonse object
Return type: Raises: - method (
-
start_login_server
()[source]¶ Start a server that will get a request from a user logging in.
This uses the Implicit Grant Flow of OAuth2. The user is asked to login to twitch and grant PyTwitcher authorization. Once the user agrees, he is redirected to an url. This server will respond to that url and get the oauth token.
The server serves in another thread. To shut him down, call
TwitchSession.shutdown_login_server()
.This sets the
TwitchSession.login_server
,TwitchSession.login_thread
variables.Returns: The created server Return type: BaseHTTPServer.HTTPServer
Raises: None
-