From 797237d9fc0d43c827cbd40510c9acd9344dd74d Mon Sep 17 00:00:00 2001 From: Adam Jacob Muller Date: Fri, 16 Nov 2012 17:09:49 -0500 Subject: [PATCH] add an auth_method paramater to Client.request to explicetly set the type of auth we want (body/authorization header/query string) --- oauth2/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/oauth2/__init__.py b/oauth2/__init__.py index 835270e3..029b25fc 100644 --- a/oauth2/__init__.py +++ b/oauth2/__init__.py @@ -637,7 +637,7 @@ def set_signature_method(self, method): self.method = method def request(self, uri, method="GET", body='', headers=None, - redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None): + redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None,auth_method=None): DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded' if not isinstance(headers, dict): @@ -670,11 +670,19 @@ def request(self, uri, method="GET", body='', headers=None, realm = schema + ':' + hierpart + host - if is_form_encoded: + if auth_method is None: + if is_form_encoded: + auth_method="body" + elif method == "GET": + auth_method="query_string" + else: + auth_method="authorization" + + if auth_method == "body": body = req.to_postdata() - elif method == "GET": + elif auth_method == "query_string": uri = req.to_url() - else: + elif auth_method == "authorization": headers.update(req.to_header(realm=realm)) return httplib2.Http.request(self, uri, method=method, body=body,