def request(<EOL>self,<EOL>method,<EOL>url,<EOL>data=None,<EOL>headers=None,<EOL>withhold_token=False,<EOL>client_id=None,<EOL>client_secret=None,<EOL>**kwargs<EOL>):
if not is_secure_transport(url):<EOL><INDENT>raise InsecureTransportError()<EOL><DEDENT>if self.token and not withhold_token:<EOL><INDENT>log.debug(<EOL>"<STR_LIT>",<EOL>len(self.compliance_hook["<STR_LIT>"]),<EOL>)<EOL>for hook in self.compliance_hook["<STR_LIT>"]:<EOL><INDENT>log.debug("<STR_LIT>", hook)<EOL>url, headers, data = hook(url, headers, data)<EOL><DEDENT>log.debug("<STR_LIT>", self.token)<EOL>try:<EOL><INDENT>url, headers, data = self._client.add_token(<EOL>url, http_method=method, body=data, headers=headers<EOL>)<EOL><DEDENT>except TokenExpiredError:<EOL><INDENT>if self.auto_refresh_url:<EOL><INDENT>log.debug(<EOL>"<STR_LIT>",<EOL>self.auto_refresh_url,<EOL>)<EOL>auth = kwargs.pop("<STR_LIT>", None)<EOL>if client_id and client_secret and (auth is None):<EOL><INDENT>log.debug(<EOL>'<STR_LIT>',<EOL>client_id,<EOL>)<EOL>auth = requests.auth.HTTPBasicAuth(client_id, client_secret)<EOL><DEDENT>token = self.refresh_token(<EOL>self.auto_refresh_url, auth=auth, **kwargs<EOL>)<EOL>if self.token_updater:<EOL><INDENT>log.debug(<EOL>"<STR_LIT>", token, self.token_updater<EOL>)<EOL>self.token_updater(token)<EOL>url, headers, data = self._client.add_token(<EOL>url, http_method=method, body=data, headers=headers<EOL>)<EOL><DEDENT>else:<EOL><INDENT>raise TokenUpdated(token)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT><DEDENT>log.debug("<STR_LIT>", url, method)<EOL>log.debug("<STR_LIT>", headers, data)<EOL>log.debug("<STR_LIT>", kwargs)<EOL>return super(OAuth2Session, self).request(<EOL>method, url, headers=headers, data=data, **kwargs<EOL>)<EOL>
Intercept all requests and add the OAuth 2 token if present.