Skip to content

Commit 03bf8a5

Browse files
dougiretonjoestump
authored andcommitted
Correctly encode Request.get_normalized_parameters
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 "+"
1 parent 39ebd39 commit 03bf8a5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

oauth2/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,12 @@ def get_parameter(self, parameter):
325325
def get_normalized_parameters(self):
326326
"""Return a string that contains the parameters that must be signed."""
327327
items = [(k, v) for k, v in self.items() if k != 'oauth_signature']
328-
return urllib.urlencode(sorted(items))
328+
encoded_str = urllib.urlencode(sorted(items))
329+
# Encode signature parameters per Oauth Core 1.0 protocol
330+
# spec draft 7, section 3.6
331+
# (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)
332+
# Spaces must be encoded with "%20" instead of "+"
333+
return encoded_str.replace('+', '%20')
329334

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

0 commit comments

Comments
 (0)