Skip to content

Commit

Permalink
Correctly encode Request.get_normalized_parameters
Browse files Browse the repository at this point in the history
Encode signature parameters per Oauth Core 1.0 protocol
spec draft 7, section 3.6
(http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)
Spaces must be encoded with "%20" instead of "+"

For example, Twitter will return "Incorrect Signature" if you
encode spaces in parameters as "+"
  • Loading branch information
dougireton authored and joestump committed Dec 4, 2009
1 parent 39ebd39 commit 03bf8a5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ def get_parameter(self, parameter):
def get_normalized_parameters(self):
"""Return a string that contains the parameters that must be signed."""
items = [(k, v) for k, v in self.items() if k != 'oauth_signature']
return urllib.urlencode(sorted(items))
encoded_str = urllib.urlencode(sorted(items))
# Encode signature parameters per Oauth Core 1.0 protocol
# spec draft 7, section 3.6
# (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)
# Spaces must be encoded with "%20" instead of "+"
return encoded_str.replace('+', '%20')

def sign_request(self, signature_method, consumer, token):
"""Set the signature parameter to the result of sign."""
Expand Down

0 comments on commit 03bf8a5

Please sign in to comment.