Skip to content

Commit c9ce81b

Browse files
committed
Include all parameters from URL, even ones that begin with "oauth_", in signature base.
effectively reverts joestump@50ca957 fixes joestump#27 Thanks to @robhudson for the bug report and help debugging.
1 parent 56c6d9b commit c9ce81b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

oauth2/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,8 @@ def get_normalized_parameters(self):
446446
query = urlparse.urlparse(self.url)[4]
447447

448448
url_items = self._split_url_string(query).items()
449-
non_oauth_url_items = list([(to_utf8(k), to_utf8(v)) for k, v in url_items if not k.startswith('oauth_')])
450-
items.extend(non_oauth_url_items)
449+
url_items = [(to_utf8(k), to_utf8(v)) for k, v in url_items ]
450+
items.extend(url_items)
451451

452452
items.sort()
453453
encoded_str = urllib.urlencode(items)

tests/test_oauth.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,38 @@ def test_get_normalized_parameters_empty(self):
545545

546546
self.assertEquals(expected, res)
547547

548+
def test_get_normalized_parameters_from_url(self):
549+
# example copied from
550+
# https://github.com/ciaranj/node-oauth/blob/master/tests/oauth.js
551+
# which in turns says that it was copied from
552+
# http://oauth.net/core/1.0/#sig_base_example .
553+
url = "http://photos.example.net/photos?file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original"
554+
555+
req = oauth.Request("GET", url)
556+
557+
res = req.get_normalized_parameters()
558+
559+
expected = 'file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original'
560+
561+
self.assertEquals(expected, res)
562+
563+
def test_signing_base(self):
564+
# example copied from
565+
# https://github.com/ciaranj/node-oauth/blob/master/tests/oauth.js
566+
# which in turns says that it was copied from
567+
# http://oauth.net/core/1.0/#sig_base_example .
568+
url = "http://photos.example.net/photos?file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original"
569+
570+
req = oauth.Request("GET", url)
571+
572+
sm = oauth.SignatureMethod_HMAC_SHA1()
573+
574+
consumer = oauth.Consumer('dpf43f3p2l4k3l03', 'foo')
575+
key, raw = sm.signing_base(req, consumer, None)
576+
577+
expected = 'GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal'
578+
self.assertEquals(expected, raw)
579+
548580
def test_get_normalized_parameters(self):
549581
url = "http://sp.example.com/"
550582

0 commit comments

Comments
 (0)