Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not all servers support every parameter transmission method #53

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class Client(httplib2.Http):
"""OAuthClient is a worker to attempt to execute a request."""

def __init__(self, consumer, token=None, cache=None, timeout=None,
proxy_info=None):
proxy_info=None, parameter_method=None):

if consumer is not None and not isinstance(consumer, Consumer):
raise ValueError("Invalid consumer.")
Expand All @@ -608,6 +608,7 @@ def __init__(self, consumer, token=None, cache=None, timeout=None,
self.consumer = consumer
self.token = token
self.method = SignatureMethod_HMAC_SHA1()
self.parameter_method = parameter_method

httplib2.Http.__init__(self, cache=cache, timeout=timeout, proxy_info=proxy_info)

Expand All @@ -618,7 +619,8 @@ 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,
parameter_method=None):
DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded'

if not isinstance(headers, dict):
Expand Down Expand Up @@ -651,12 +653,24 @@ def request(self, uri, method="GET", body='', headers=None,

realm = schema + ':' + hierpart + host

if is_form_encoded:
parameter_method = parameter_method or self.parameter_method

if parameter_method is None:
if is_form_encoded:
parameter_method = 'body'
elif method == "GET":
parameter_method = 'query'
else:
parameter_method = 'header'

if parameter_method == 'header':
headers.update(req.to_header(realm=realm))
elif parameter_method == 'body':
body = req.to_postdata()
elif method == "GET":
elif parameter_method == 'query':
uri = req.to_url()
else:
headers.update(req.to_header(realm=realm))
raise ValueError('Invalid parameter_method: %s' % parameter_method)

return httplib2.Http.request(self, uri, method=method, body=body,
headers=headers, redirections=redirections,
Expand Down