From 95dbff6d7ae0ab2b0a92204cf1e10dce7f403cba Mon Sep 17 00:00:00 2001
From: Sylvain <sylvain.desodt+github@gmail.com>
Date: Wed, 8 Mar 2017 15:26:57 +0100
Subject: [PATCH 01/10] Add most recent Python versions in Travis CI

Add more recent Python versions including development branches and nightly build.
---
 .travis.yml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/.travis.yml b/.travis.yml
index a20f7099..32191e78 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,6 +4,11 @@ python:
   - "2.7"
   - "3.3"
   - "3.4"
+  - "3.5"
+  - "3.6"
+  - "3.6-dev"
+  - "3.7-dev"
+  - "nightly"
 install:
   - pip install -r requirements.txt
   - pip install codecov pytest-cov

From 7dd5d758120d64dd7ad8a0b1af10e6283a7320aa Mon Sep 17 00:00:00 2001
From: Nik Nyby <nnyby@columbia.edu>
Date: Mon, 23 Oct 2017 13:45:27 -0400
Subject: [PATCH 02/10] Remove python 3.3, add python 3.5 and 3.6

Python 3.3 has reached end of life: https://www.python.org/downloads/release/python-336/
---
 .travis.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index a20f7099..ad53945a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,8 +2,9 @@ language: python
 python:
   - "2.6"
   - "2.7"
-  - "3.3"
   - "3.4"
+  - "3.5"
+  - "3.6"
 install:
   - pip install -r requirements.txt
   - pip install codecov pytest-cov

From 3e388933417dcfa6fa1e8487b2014be9c900e754 Mon Sep 17 00:00:00 2001
From: martyni <martynjamespratt@gmail.com>
Date: Fri, 10 Nov 2017 12:50:32 +0000
Subject: [PATCH 03/10] bug fix

---
 oauth2/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/oauth2/__init__.py b/oauth2/__init__.py
index a1776a75..cc64ae80 100644
--- a/oauth2/__init__.py
+++ b/oauth2/__init__.py
@@ -490,7 +490,7 @@ def sign_request(self, signature_method, consumer, token):
             # section 4.1.1 "OAuth Consumers MUST NOT include an
             # oauth_body_hash parameter on requests with form-encoded
             # request bodies."
-            self['oauth_body_hash'] = base64.b64encode(sha1(self.body).digest())
+            self['oauth_body_hash'] = base64.b64encode(sha1(u'{}'.format(self.body)).digest())
 
         if 'oauth_consumer_key' not in self:
             self['oauth_consumer_key'] = consumer.key

From 7de768862e19185aca941784c16f9abf171e2c20 Mon Sep 17 00:00:00 2001
From: martyni <martynjamespratt@gmail.com>
Date: Fri, 10 Nov 2017 13:00:05 +0000
Subject: [PATCH 04/10] removed unicode str

---
 oauth2/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/oauth2/__init__.py b/oauth2/__init__.py
index cc64ae80..73817f36 100644
--- a/oauth2/__init__.py
+++ b/oauth2/__init__.py
@@ -490,7 +490,7 @@ def sign_request(self, signature_method, consumer, token):
             # section 4.1.1 "OAuth Consumers MUST NOT include an
             # oauth_body_hash parameter on requests with form-encoded
             # request bodies."
-            self['oauth_body_hash'] = base64.b64encode(sha1(u'{}'.format(self.body)).digest())
+            self['oauth_body_hash'] = base64.b64encode(sha1('{}'.format(self.body)).digest())
 
         if 'oauth_consumer_key' not in self:
             self['oauth_consumer_key'] = consumer.key

From 0295f507df9c2de07e2b985987d70fefcf1c51f2 Mon Sep 17 00:00:00 2001
From: martyni <martynjamespratt@gmail.com>
Date: Fri, 10 Nov 2017 13:05:13 +0000
Subject: [PATCH 05/10] bug fix

---
 oauth2/__init__.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/oauth2/__init__.py b/oauth2/__init__.py
index 73817f36..3849b06f 100644
--- a/oauth2/__init__.py
+++ b/oauth2/__init__.py
@@ -490,7 +490,9 @@ def sign_request(self, signature_method, consumer, token):
             # section 4.1.1 "OAuth Consumers MUST NOT include an
             # oauth_body_hash parameter on requests with form-encoded
             # request bodies."
-            self['oauth_body_hash'] = base64.b64encode(sha1('{}'.format(self.body)).digest())
+            if not self.body:
+               self.body = ''
+            self['oauth_body_hash'] = base64.b64encode(sha1(self.body).digest())
 
         if 'oauth_consumer_key' not in self:
             self['oauth_consumer_key'] = consumer.key

From 46bbc5ea27da68e776b5e2f1aa3b8d6c6905653f Mon Sep 17 00:00:00 2001
From: martyni <martynjamespratt@gmail.com>
Date: Fri, 10 Nov 2017 13:11:11 +0000
Subject: [PATCH 06/10] testing

---
 oauth2/__init__.py | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/oauth2/__init__.py b/oauth2/__init__.py
index 3849b06f..1b56ee14 100644
--- a/oauth2/__init__.py
+++ b/oauth2/__init__.py
@@ -489,9 +489,7 @@ def sign_request(self, signature_method, consumer, token):
             # http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
             # section 4.1.1 "OAuth Consumers MUST NOT include an
             # oauth_body_hash parameter on requests with form-encoded
-            # request bodies."
-            if not self.body:
-               self.body = ''
+            # request bodies. "
             self['oauth_body_hash'] = base64.b64encode(sha1(self.body).digest())
 
         if 'oauth_consumer_key' not in self:

From d4b0b6d6d12a2fe519a12e6fe9b80ac2fef6b9c8 Mon Sep 17 00:00:00 2001
From: martyni <martynjamespratt@gmail.com>
Date: Fri, 10 Nov 2017 13:21:50 +0000
Subject: [PATCH 07/10] encoded to utf-8

---
 oauth2/__init__.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/oauth2/__init__.py b/oauth2/__init__.py
index 1b56ee14..0e02e62e 100644
--- a/oauth2/__init__.py
+++ b/oauth2/__init__.py
@@ -489,7 +489,9 @@ def sign_request(self, signature_method, consumer, token):
             # http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
             # section 4.1.1 "OAuth Consumers MUST NOT include an
             # oauth_body_hash parameter on requests with form-encoded
-            # request bodies. "
+            # request bodies."
+            if not self.body:
+               self.body = ''.encode('utf-8')
             self['oauth_body_hash'] = base64.b64encode(sha1(self.body).digest())
 
         if 'oauth_consumer_key' not in self:

From bc8b38024ba723acb6f89ce32658d28ea9a61c34 Mon Sep 17 00:00:00 2001
From: Tim Sheerman-Chase <tim2009@sheerman-chase.org.uk>
Date: Mon, 4 Dec 2017 04:24:22 +0000
Subject: [PATCH 08/10] Test for issue #207

---
 tests/test_oauth.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/tests/test_oauth.py b/tests/test_oauth.py
index 58854564..b9802cbc 100644
--- a/tests/test_oauth.py
+++ b/tests/test_oauth.py
@@ -1210,7 +1210,7 @@ def sign(self, request, consumer, token):
 
 class TestServer(unittest.TestCase):
     def setUp(self):
-        url = "http://sp.example.com/"
+        self.url = "http://sp.example.com/"
 
         params = {
             'oauth_version': "1.0",
@@ -1227,7 +1227,7 @@ def setUp(self):
 
         params['oauth_token'] = self.token.key
         params['oauth_consumer_key'] = self.consumer.key
-        self.request = oauth.Request(method="GET", url=url, parameters=params)
+        self.request = oauth.Request(method="GET", url=self.url, parameters=params)
 
         signature_method = oauth.SignatureMethod_HMAC_SHA1()
         self.request.sign_request(signature_method, self.consumer, self.token)
@@ -1269,6 +1269,18 @@ def test_verify_request(self):
         self.assertEqual(parameters['foo'], 59)
         self.assertEqual(parameters['multi'], ['FOO','BAR'])
 
+    def test_verify_request_query_string(self):
+        server = oauth.Server()
+        server.add_signature_method(oauth.SignatureMethod_HMAC_SHA1())
+
+        signature_method = oauth.SignatureMethod_HMAC_SHA1()
+        request2 = oauth.Request.from_request("GET", self.url, query_string=urlencode(dict(self.request)))
+        request2.sign_request(signature_method, self.consumer, self.token)
+        request3 = oauth.Request.from_request("GET", self.url, query_string=urlencode(dict(request2)))        
+
+        parameters = server.verify_request(request3, self.consumer,
+            self.token)
+
     def test_verify_request_missing_signature(self):
         from oauth2 import MissingSignature
         server = oauth.Server()

From 281efc499d188b26e05f913ff8c0c2089e6a39bf Mon Sep 17 00:00:00 2001
From: Tim Sheerman-Chase <tim2009@sheerman-chase.org.uk>
Date: Mon, 4 Dec 2017 05:03:24 +0000
Subject: [PATCH 09/10] Hacky fix for #207

---
 oauth2/__init__.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/oauth2/__init__.py b/oauth2/__init__.py
index a1776a75..e588199e 100644
--- a/oauth2/__init__.py
+++ b/oauth2/__init__.py
@@ -353,6 +353,7 @@ def __init__(self, method=HTTP_METHOD, url=None, parameters=None,
             for k, v in parameters.items():
                 k = to_unicode(k)
                 v = to_unicode_optional_iterator(v)
+
                 self[k] = v
         self.body = body
         self.is_form_encoded = is_form_encoded
@@ -540,6 +541,7 @@ def from_request(cls, http_method, http_url, headers=None, parameters=None,
         # GET or POST query string.
         if query_string:
             query_params = cls._split_url_string(query_string)
+
             parameters.update(query_params)
  
         # URL parameters.
@@ -757,6 +759,8 @@ def _check_signature(self, request, consumer, token):
         signature = request.get('oauth_signature')
         if signature is None:
             raise MissingSignature('Missing oauth_signature.')
+        if isinstance(signature, str):
+            signature = signature.encode('ascii', 'ignore')
 
         # Validate the signature.
         valid = signature_method.check(request, consumer, token, signature)

From 631e8a517a924081efd433976d8b413f932f4cc0 Mon Sep 17 00:00:00 2001
From: Igor Cheledinov <cheledinov@gmail.com>
Date: Tue, 23 Jan 2018 00:08:23 +0300
Subject: [PATCH 10/10] fix problem with python3.6

---
 oauth2/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/oauth2/__init__.py b/oauth2/__init__.py
index a1776a75..bbc8763b 100644
--- a/oauth2/__init__.py
+++ b/oauth2/__init__.py
@@ -490,7 +490,7 @@ def sign_request(self, signature_method, consumer, token):
             # section 4.1.1 "OAuth Consumers MUST NOT include an
             # oauth_body_hash parameter on requests with form-encoded
             # request bodies."
-            self['oauth_body_hash'] = base64.b64encode(sha1(self.body).digest())
+            self['oauth_body_hash'] = base64.b64encode(sha1(to_utf8(self.body)).digest())
 
         if 'oauth_consumer_key' not in self:
             self['oauth_consumer_key'] = consumer.key
