From b2ae546a48eadcd56c35d368e697046c9d318cab Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Wed, 18 Mar 2020 13:18:55 +0100 Subject: [PATCH 1/9] adapt to werkzeug 1.0.0 import cached_property from werkzeug.utils --- flask_oauthlib/client.py | 2 +- flask_oauthlib/provider/oauth1.py | 2 +- flask_oauthlib/provider/oauth2.py | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index 3b1cc278..b76eaf90 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -16,7 +16,7 @@ from oauthlib.common import to_unicode, PY3, add_params_to_uri from flask import request, redirect, json, session, current_app from werkzeug import url_quote, url_decode, url_encode -from werkzeug import parse_options_header, cached_property +from werkzeug.utils import parse_options_header, cached_property from .utils import to_bytes try: from urlparse import urljoin diff --git a/flask_oauthlib/provider/oauth1.py b/flask_oauthlib/provider/oauth1.py index eb5fdba0..ec517e19 100644 --- a/flask_oauthlib/provider/oauth1.py +++ b/flask_oauthlib/provider/oauth1.py @@ -10,7 +10,7 @@ import logging from functools import wraps -from werkzeug import cached_property +from werkzeug.utils import cached_property from flask import request, redirect, url_for from flask import make_response, abort from oauthlib.oauth1 import RequestValidator diff --git a/flask_oauthlib/provider/oauth2.py b/flask_oauthlib/provider/oauth2.py index 23eed415..b3b9a889 100644 --- a/flask_oauthlib/provider/oauth2.py +++ b/flask_oauthlib/provider/oauth2.py @@ -14,8 +14,7 @@ from functools import wraps from flask import request, url_for from flask import redirect, abort -from werkzeug import cached_property -from werkzeug.utils import import_string +from werkzeug.utils import cached_property, import_string from oauthlib import oauth2 from oauthlib.oauth2 import RequestValidator, Server from oauthlib.common import to_unicode, add_params_to_uri @@ -472,7 +471,7 @@ def decorated(*args, **kwargs): # denied by user e = oauth2.AccessDeniedError(state=request.values.get('state')) return self._on_exception(e, e.in_uri(redirect_uri)) - + return self.confirm_authorization_request() return decorated @@ -502,7 +501,7 @@ def confirm_authorization_request(self): return self._on_exception(e, e.in_uri(self.error_uri)) except oauth2.OAuth2Error as e: log.debug('OAuth2Error: %r', e, exc_info=True) - + # on auth error, we should preserve state if it's present according to RFC 6749 state = request.values.get('state') if state and not e.state: From f9803a98aea31f4508455aeb631d33a75969580f Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Wed, 18 Mar 2020 13:37:55 +0100 Subject: [PATCH 2/9] import url helpers from werkzeug.urls --- flask_oauthlib/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index b76eaf90..da348ba5 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -15,7 +15,7 @@ from functools import wraps from oauthlib.common import to_unicode, PY3, add_params_to_uri from flask import request, redirect, json, session, current_app -from werkzeug import url_quote, url_decode, url_encode +from werkzeug.urls import url_quote, url_decode, url_encode from werkzeug.utils import parse_options_header, cached_property from .utils import to_bytes try: From 42ab8d5b3adaf97e472b9a601758684b11bd01e6 Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Wed, 18 Mar 2020 13:39:33 +0100 Subject: [PATCH 3/9] but import parse_options_header from werkzeug directly --- flask_oauthlib/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index da348ba5..f265354b 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -15,8 +15,9 @@ from functools import wraps from oauthlib.common import to_unicode, PY3, add_params_to_uri from flask import request, redirect, json, session, current_app +from werkzeug import parse_options_header from werkzeug.urls import url_quote, url_decode, url_encode -from werkzeug.utils import parse_options_header, cached_property +from werkzeug.utils import cached_property from .utils import to_bytes try: from urlparse import urljoin From dcb90c47afeceafb90920be091860fc3cbed4b07 Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Wed, 18 Mar 2020 13:41:06 +0100 Subject: [PATCH 4/9] nop, it's in the http submodule --- flask_oauthlib/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index f265354b..83c1de48 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -15,7 +15,7 @@ from functools import wraps from oauthlib.common import to_unicode, PY3, add_params_to_uri from flask import request, redirect, json, session, current_app -from werkzeug import parse_options_header +from werkzeug.http import parse_options_header from werkzeug.urls import url_quote, url_decode, url_encode from werkzeug.utils import cached_property from .utils import to_bytes From f96f6910abd2521f3c17ce6e65371ae3a16b6f11 Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Tue, 24 Mar 2020 16:30:01 +0100 Subject: [PATCH 5/9] fix imports. no need for dynamic byte_type, python3 has a native byte type --- flask_oauthlib/contrib/apps.py | 4 ++-- flask_oauthlib/contrib/cache.py | 4 ++-- flask_oauthlib/utils.py | 4 ++-- requirements.txt | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/flask_oauthlib/contrib/apps.py b/flask_oauthlib/contrib/apps.py index 09b67e88..d2820cbd 100644 --- a/flask_oauthlib/contrib/apps.py +++ b/flask_oauthlib/contrib/apps.py @@ -31,7 +31,7 @@ import copy -from oauthlib.common import unicode_type, bytes_type +from oauthlib.common import unicode_type __all__ = ['douban', 'dropbox', 'facebook', 'github', 'google', 'linkedin', @@ -87,7 +87,7 @@ def make_scope_processor(default_scope): def processor(**kwargs): # request_token_params scope = kwargs.pop('scope', [default_scope]) # default scope - if not isinstance(scope, (unicode_type, bytes_type)): + if not isinstance(scope, (unicode_type, bytes)): scope = ','.join(scope) # allows list-style scope request_token_params = kwargs.setdefault('request_token_params', {}) request_token_params.setdefault('scope', scope) # doesn't override diff --git a/flask_oauthlib/contrib/cache.py b/flask_oauthlib/contrib/cache.py index f8788aa7..6adb62e1 100644 --- a/flask_oauthlib/contrib/cache.py +++ b/flask_oauthlib/contrib/cache.py @@ -1,7 +1,7 @@ # coding: utf-8 -from werkzeug.contrib.cache import NullCache, SimpleCache, FileSystemCache -from werkzeug.contrib.cache import MemcachedCache, RedisCache +from cachelib import NullCache, SimpleCache, FileSystemCache +from cachelib import MemcachedCache, RedisCache class Cache(object): diff --git a/flask_oauthlib/utils.py b/flask_oauthlib/utils.py index 5a7b5013..44a1a721 100644 --- a/flask_oauthlib/utils.py +++ b/flask_oauthlib/utils.py @@ -2,7 +2,7 @@ import base64 from flask import request, Response -from oauthlib.common import to_unicode, bytes_type +from oauthlib.common import to_unicode def _get_uri_from_request(request): @@ -41,7 +41,7 @@ def to_bytes(text, encoding='utf-8'): """Make sure text is bytes type.""" if not text: return text - if not isinstance(text, bytes_type): + if not isinstance(text, bytes): text = text.encode(encoding) return text diff --git a/requirements.txt b/requirements.txt index 4cc5d916..e122b41f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Flask>=0.12.3 +cachelib==0.1 mock==2.0.0 oauthlib==2.0.6 requests-oauthlib==0.8.0 From 4f18e1a187da36f2798901f32d8283409a65312a Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Mon, 10 Jan 2022 13:37:20 +0100 Subject: [PATCH 6/9] remove python version check and string_types. assume py3 and str the only string type --- flask_oauthlib/client.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index 83c1de48..781c3534 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -13,7 +13,7 @@ import oauthlib.oauth2 from copy import copy from functools import wraps -from oauthlib.common import to_unicode, PY3, add_params_to_uri +from oauthlib.common import to_unicode, add_params_to_uri from flask import request, redirect, json, session, current_app from werkzeug.http import parse_options_header from werkzeug.urls import url_quote, url_decode, url_encode @@ -28,12 +28,6 @@ log = logging.getLogger('flask_oauthlib') -if PY3: - string_types = (str,) -else: - string_types = (str, unicode) - - __all__ = ('OAuth', 'OAuthRemoteApp', 'OAuthResponse', 'OAuthException') @@ -385,7 +379,7 @@ def make_client(self, token=None): if token: if isinstance(token, (tuple, list)): token = {'access_token': token[0]} - elif isinstance(token, string_types): + elif isinstance(token, str): token = {'access_token': token} client = oauthlib.oauth2.WebApplicationClient( self.consumer_key, token=token From 910fb23f52bfa77be27541bd40a22eb081272fd9 Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Tue, 11 Jan 2022 13:13:29 +0100 Subject: [PATCH 7/9] remove more python version checking --- flask_oauthlib/client.py | 5 ----- tests/test_client.py | 6 ------ 2 files changed, 11 deletions(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index 781c3534..20536fc1 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -180,11 +180,6 @@ def __init__(self, message, type=None, data=None): self.data = data def __str__(self): - if PY3: - return self.message - return self.message.encode('utf-8') - - def __unicode__(self): return self.message diff --git a/tests/test_client.py b/tests/test_client.py index 81d64893..0ca217b4 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -3,7 +3,6 @@ from flask_oauthlib.client import encode_request_data from flask_oauthlib.client import OAuthRemoteApp, OAuth from flask_oauthlib.client import parse_response -from oauthlib.common import PY3 try: import urllib2 as http @@ -194,11 +193,6 @@ def test_token_types(self): client_token = {'access_token': 'access token'} - if not PY3: - unicode_token = u'access token' - client = remote.make_client(token=unicode_token) - assert client.token == client_token - str_token = 'access token' client = remote.make_client(token=str_token) assert client.token == client_token From b6ee874706834555985492a96184de35d6884211 Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Tue, 11 Jan 2022 13:30:35 +0100 Subject: [PATCH 8/9] remove dox submodule --- .gitmodules | 3 --- docs/_themes | 1 - 2 files changed, 4 deletions(-) delete mode 160000 docs/_themes diff --git a/.gitmodules b/.gitmodules index 23fe0c1e..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "docs/_themes"] - path = docs/_themes - url = git://github.com/lepture/flask-sphinx-themes.git diff --git a/docs/_themes b/docs/_themes deleted file mode 160000 index 7baf93a0..00000000 --- a/docs/_themes +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7baf93a01fc3adb32460b59d1e88bc8f9c2cf617 From 6612775abd0aa3f0f0d2b45ea9ef10e3cb044a3e Mon Sep 17 00:00:00 2001 From: Ulrich Berthold Date: Fri, 5 Apr 2024 14:59:40 +0200 Subject: [PATCH 9/9] replace werkzeug url helpers with urllibs' --- flask_oauthlib/client.py | 18 ++++++++++-------- requirements.txt | 1 + tests/_base.py | 2 -- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/flask_oauthlib/client.py b/flask_oauthlib/client.py index 20536fc1..8a4afadf 100644 --- a/flask_oauthlib/client.py +++ b/flask_oauthlib/client.py @@ -16,15 +16,14 @@ from oauthlib.common import to_unicode, add_params_to_uri from flask import request, redirect, json, session, current_app from werkzeug.http import parse_options_header -from werkzeug.urls import url_quote, url_decode, url_encode +from urllib.parse import parse_qsl, quote, urlencode, urlparse, urljoin from werkzeug.utils import cached_property from .utils import to_bytes try: - from urlparse import urljoin import urllib2 as http except ImportError: from urllib import request as http - from urllib.parse import urljoin + log = logging.getLogger('flask_oauthlib') @@ -127,9 +126,12 @@ def parse_response(resp, content, strict=False, content_type=None): if ct != 'application/x-www-form-urlencoded' and strict: return content - charset = options.get('charset', 'utf-8') - return url_decode(content, charset=charset).to_dict() + charset = options.get('charset', 'utf-8') + parsed = urlparse(content) + return parse_qsl( + parsed.query, encoding=charset, strict_parsing=strict, keep_blank_values=True + ) def prepare_request(uri, headers=None, data=None, method=None): """Make request parameters right.""" @@ -154,7 +156,7 @@ def encode_request_data(data, format): if format == 'json': return json.dumps(data or {}), 'application/json' if format == 'urlencoded': - return url_encode(data or {}), 'application/x-www-form-urlencoded' + return urlencode(data or {}, encoding='application/x-www-form-urlencoded') raise TypeError('Unknown format %r' % format) @@ -512,10 +514,10 @@ def authorize(self, callback=None, state=None, **kwargs): if self.request_token_url: token = self.generate_request_token(callback)[0] url = '%s?oauth_token=%s' % ( - self.expand_url(self.authorize_url), url_quote(token) + self.expand_url(self.authorize_url), quote(token) ) if params: - url += '&' + url_encode(params) + url += '&' + urlencode(params) else: assert callback is not None, 'Callback is required for OAuth2' diff --git a/requirements.txt b/requirements.txt index e122b41f..0fd727c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +werkzeug>=3.0.1 Flask>=0.12.3 cachelib==0.1 mock==2.0.0 diff --git a/tests/_base.py b/tests/_base.py index c14bbb3a..9d17508b 100644 --- a/tests/_base.py +++ b/tests/_base.py @@ -1,5 +1,3 @@ -# coding: utf-8 - import base64 import os import sys