Skip to content

Commit 10fb61a

Browse files
Woodyajoestump
authored andcommitted
as per 1.0a/9.1.1 part 1: Parameters are sorted by name, using lexicographical byte value ordering. If two or more parameters share the same name, they are sorted by their value
1 parent b9fdc6c commit 10fb61a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

oauth2/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import hmac
3030
import binascii
3131
import httplib2
32+
from types import ListType
3233

3334
try:
3435
from urlparse import parse_qs, parse_qsl
@@ -327,8 +328,9 @@ def get_parameter(self, parameter):
327328

328329
def get_normalized_parameters(self):
329330
"""Return a string that contains the parameters that must be signed."""
330-
items = [(k, v) for k, v in self.items() if k != 'oauth_signature']
331-
encoded_str = urllib.urlencode(sorted(items), True)
331+
# 1.0a/9.1.1 states that kvp must be sorted by key, then by value
332+
items = [(k, v if type(v) != ListType else sorted(v)) for k,v in sorted(self.items()) if k != 'oauth_signature']
333+
encoded_str = urllib.urlencode(items, True)
332334
# Encode signature parameters per Oauth Core 1.0 protocol
333335
# spec draft 7, section 3.6
334336
# (http://tools.ietf.org/html/draft-hammer-oauth-07#section-3.6)

tests/test_oauth.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import time
3131
import urllib
3232
import urlparse
33+
from types import ListType
3334

3435

3536
# Fix for python2.5 compatibility
@@ -372,13 +373,16 @@ def test_get_normalized_parameters(self):
372373
'oauth_consumer_key': "0685bd9184jfhq22",
373374
'oauth_signature_method': "HMAC-SHA1",
374375
'oauth_token': "ad180jjd733klru7",
376+
'multi': ['FOO','BAR'],
375377
}
376378

377379
req = oauth.Request("GET", url, params)
378380

379381
res = req.get_normalized_parameters()
382+
383+
srtd = [(k, v if type(v) != ListType else sorted(v)) for k,v in sorted(params.items())]
380384

381-
self.assertEquals(urllib.urlencode(sorted(params.items())), res)
385+
self.assertEquals(urllib.urlencode(srtd, True), res)
382386

383387
def test_get_normalized_parameters_ignores_auth_signature(self):
384388
url = "http://sp.example.com/"

0 commit comments

Comments
 (0)