Skip to content

Commit

Permalink
Merge pull request #371 from SONIFI/master
Browse files Browse the repository at this point in the history
Python3 fix: encodes request body before hashing
  • Loading branch information
thedrow committed Aug 10, 2015
2 parents d8a920a + 5c81414 commit 1b0de72
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions oauthlib/oauth1/rfc5849/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ def get_oauth_params(self, request):
# as described in http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
# 4.1.1. When to include the body hash
# * [...] MUST NOT include an oauth_body_hash parameter on requests with form-encoded request bodies
# * [...] SHOULD include the oauth_body_hash parameter on all other requests.
# * [...] SHOULD include the oauth_body_hash parameter on all other requests.
content_type = request.headers.get('Content-Type', None)
content_type_eligible = content_type and content_type.find('application/x-www-form-urlencoded') < 0
if request.body is not None and content_type_eligible:
params.append(('oauth_body_hash', base64.b64encode(hashlib.sha1(request.body).digest()).decode('utf-8')))
params.append(('oauth_body_hash', base64.b64encode(hashlib.sha1(request.body.encode('utf-8')).digest()).decode('utf-8')))

return params

Expand Down

0 comments on commit 1b0de72

Please sign in to comment.