Skip to content

Commit 28af426

Browse files
committed
Specification improvement and bug fix to sign_request
Per the OAuth Body Hash specifications (3.2)[1], if there is no body entity, then the hash should be done over the empty string. Also, when httplib2 handles a redirect, the follow is performed with None as the request body. This causes a TypeError to be thrown when attempting to hash the body here. This commit fixes the bug while improving the specification alignment. [1]http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
1 parent a83f4a2 commit 28af426

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

oauth2/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,14 @@ def sign_request(self, signature_method, consumer, token):
485485
"""Set the signature parameter to the result of sign."""
486486

487487
if not self.is_form_encoded:
488-
# according to
488+
# according to
489489
# http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
490+
# section 3.2 "If the request does not have an entity body, the hash should
491+
# be taken over the empty string."
492+
if self.body is None:
493+
self.body = ""
494+
495+
# according to ibid
490496
# section 4.1.1 "OAuth Consumers MUST NOT include an
491497
# oauth_body_hash parameter on requests with form-encoded
492498
# request bodies."

0 commit comments

Comments
 (0)