pytwitcherapi.oauth.TwitchOAuthClient¶
-
class
pytwitcherapi.oauth.
TwitchOAuthClient
(client_id, default_token_placement=u'auth_header', token_type=u'Bearer', access_token=None, refresh_token=None, mac_key=None, mac_algorithm=None, token=None, scope=None, state=None, redirect_url=None, state_generator=<function generate_token>, **kwargs)[source]¶ Bases:
oauthlib.oauth2.rfc6749.clients.mobile_application.MobileApplicationClient
This is a client needed for
oauthlib.oauth2.OAuth2Session
. It fixes the Authorization header for twitch.Usually the Authorization Header looks like this:
{'Authorization': 'Bearer <<token>>'}
But Twitch needs it to be like this:
{'Authorization': 'OAuth <<token>>'}
So we override
TwitchOAuthClient._add_bearer_token()
to fix the header.-
__init__
(client_id, default_token_placement=u'auth_header', token_type=u'Bearer', access_token=None, refresh_token=None, mac_key=None, mac_algorithm=None, token=None, scope=None, state=None, redirect_url=None, state_generator=<function generate_token>, **kwargs)¶ Initialize a client with commonly used attributes.
Parameters: client_id – Client identifier given by the OAuth provider upon registration.
Parameters: default_token_placement – Tokens can be supplied in the Authorization header (default), the URL query component (
query
) or the request body (body
).Parameters: token_type – OAuth 2 token type. Defaults to Bearer. Change this if you specify the
access_token
parameter and know it is of a different token type, such as a MAC, JWT or SAML token. Can also be supplied astoken_type
inside thetoken
dict parameter.Parameters: access_token – An access token (string) used to authenticate requests to protected resources. Can also be supplied inside the
token
dict parameter.Parameters: refresh_token – A refresh token (string) used to refresh expired tokens. Can also be supplied inside the
token
dict parameter.Parameters: - mac_key – Encryption key used with MAC tokens.
- mac_algorithm – Hashing algorithm for MAC tokens.
- token – A dict of token attributes such as
access_token
,
token_type
andexpires_at
.Parameters: - scope – A list of default scopes to request authorization for.
- state – A CSRF protection string used during authorization.
- redirect_url – The redirection endpoint on the client side to which
the user returns after authorization.
Parameters: state_generator – A no argument state generation callable. Defaults to
oauthlib.common.generate_token()
.
Methods
__init__
(client_id[, ...])Initialize a client with commonly used attributes. add_token
(uri[, http_method, body, headers, ...])Add token to the request uri, body or authorization header. parse_request_body_response
(body[, scope])Parse the JSON response body. parse_request_uri_response
(uri[, state, scope])Parse the response URI fragment. prepare_authorization_request
(authorization_url)Prepare the authorization request. prepare_refresh_body
([body, refresh_token, ...])Prepare an access token request, using a refresh token. prepare_refresh_token_request
(token_url[, ...])Prepare an access token refresh request. prepare_request_body
(*args, **kwargs)Abstract method used to create request bodies. prepare_request_uri
(uri[, redirect_uri, ...])Prepare the implicit grant request URI. prepare_token_request
(token_url[, ...])Prepare a token creation request. prepare_token_revocation_request
(...[, ...])Prepare a token revocation request. Attributes
token_types
Supported token types and their respective methods -