Skip to content

Commit fa248eb

Browse files
committed
py3fication
1 parent d33afd3 commit fa248eb

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

oauth2/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def __init__(self, method=HTTP_METHOD, url=None, parameters=None,
349349
k = to_unicode(k)
350350
v = to_unicode_optional_iterator(v)
351351
self[k] = v
352-
self.body = body
352+
self.body = body.encode('UTF-8')
353353
self.is_form_encoded = is_form_encoded
354354

355355

@@ -481,10 +481,10 @@ def get_normalized_parameters(self):
481481
# Spaces must be encoded with "%20" instead of "+"
482482
return encoded_str.replace('+', '%20').replace('%7E', '~')
483483

484-
def sign_request(self, signature_method, consumer, token):
484+
def sign_request(self, signature_method, consumer, token, include_body_hash=True):
485485
"""Set the signature parameter to the result of sign."""
486486

487-
if not self.is_form_encoded:
487+
if not self.is_form_encoded and include_body_hash:
488488
# according to
489489
# http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
490490
# section 4.1.1 "OAuth Consumers MUST NOT include an
@@ -637,7 +637,7 @@ def set_signature_method(self, method):
637637
self.method = method
638638

639639
def request(self, uri, method="GET", body='', headers=None,
640-
redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None):
640+
redirections=httplib2.DEFAULT_MAX_REDIRECTS, connection_type=None, include_body_hash=True):
641641
DEFAULT_POST_CONTENT_TYPE = 'application/x-www-form-urlencoded'
642642

643643
if not isinstance(headers, dict):
@@ -659,7 +659,7 @@ def request(self, uri, method="GET", body='', headers=None,
659659
token=self.token, http_method=method, http_url=uri,
660660
parameters=parameters, body=body, is_form_encoded=is_form_encoded)
661661

662-
req.sign_request(self.method, self.consumer, self.token)
662+
req.sign_request(self.method, self.consumer, self.token, include_body_hash)
663663

664664
schema, rest = urllib.parse.splittype(uri)
665665
if rest.startswith('//'):
@@ -837,10 +837,10 @@ def sign(self, request, consumer, token):
837837
"""Builds the base signature string."""
838838
key, raw = self.signing_base(request, consumer, token)
839839

840-
hashed = hmac.new(key, raw, sha)
840+
hashed = hmac.new(key.encode('UTF-8'), raw.encode('UTF-8'), sha)
841841

842842
# Calculate the digest base 64.
843-
return binascii.b2a_base64(hashed.digest())[:-1]
843+
return binascii.b2a_base64(hashed.digest())[:-1].decode('UTF-8')
844844

845845

846846
class SignatureMethod_PLAINTEXT(SignatureMethod):

0 commit comments

Comments
 (0)