From 2243ab0b5d3d6988ac7e9b0226480236f7af85c0 Mon Sep 17 00:00:00 2001 From: afabiani Date: Wed, 15 Jul 2020 17:29:13 +0200 Subject: [PATCH] Drop Django 1 / Python 2 support --- CHANGELOG.md | 4 ++++ oauth2_provider/oauth2_backends.py | 21 +++++++++++++++------ oauth2_provider/views/base.py | 2 +- setup.cfg | 12 ++++-------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89064a9..7b274d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 2.0.0 [2020-07-15] + +* 2020-07-15: afabiani Drop Django 1 / Python 2 support + ### 1.1.5 [2020-03-31] * 2020-01-31: vikipha Fixed bearer verification diff --git a/oauth2_provider/oauth2_backends.py b/oauth2_provider/oauth2_backends.py index 46366f0..e8ba197 100644 --- a/oauth2_provider/oauth2_backends.py +++ b/oauth2_provider/oauth2_backends.py @@ -1,9 +1,7 @@ import json -try: - from urllib.parse import urlparse, urlunparse -except ImportError: - from urlparse import urlparse, urlunparse +from urllib.parse import urlparse, urlunparse, urlsplit, parse_qsl +from urllib.parse import urlencode as urllib_urlencode, SplitResult from oauthlib import oauth2 from oauthlib.common import quote, urlencode, urlencoded @@ -31,8 +29,19 @@ def _get_escaped_full_path(self, request): unsafe = set(c for c in parsed[4]).difference(urlencoded) for c in unsafe: parsed[4] = parsed[4].replace(c, quote(c, safe=b"")) - - return urlunparse(parsed) + uri = urlsplit(urlunparse(parsed)) + query = uri.query + params = parse_qsl(query) + encoded_params = urllib_urlencode(params, doseq=False) + + parsed_url = SplitResult( + uri.scheme, + uri.netloc, + uri.path, + encoded_params, + uri.fragment) + + return parsed_url.geturl() def _get_extra_credentials(self, request): """ diff --git a/oauth2_provider/views/base.py b/oauth2_provider/views/base.py index 832fa9f..24095c6 100644 --- a/oauth2_provider/views/base.py +++ b/oauth2_provider/views/base.py @@ -169,7 +169,7 @@ def get(self, request, *args, **kwargs): application = get_application_model().objects.get(client_id=credentials["client_id"]) uri_query = urlparse(self.request.get_raw_uri()).query - uri_query_params = dict(parse_qsl(uri_query, keep_blank_values=True, strict_parsing=True)) + uri_query_params = dict(parse_qsl(uri_query, keep_blank_values=True, strict_parsing=False)) kwargs["application"] = application kwargs["client_id"] = credentials["client_id"] diff --git a/setup.cfg b/setup.cfg index 34079c3..6286bde 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = geonode-oauth-toolkit -version = 1.1.5 +version = 2.0.0 description = OAuth2 Provider for Django/GeoNode author = Federico Frenguelli, Massimiliano Pippi, Alessio Fabiani author_email = synasius@gmail.com @@ -10,17 +10,13 @@ classifiers = Development Status :: 5 - Production/Stable Environment :: Web Environment Framework :: Django - Framework :: Django :: 1.11 - Framework :: Django :: 2.0 + Framework :: Django :: 2.2 Intended Audience :: Developers License :: OSI Approved :: BSD License Operating System :: OS Independent - Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 Topic :: Internet :: WWW/HTTP [options] @@ -28,7 +24,7 @@ packages = find: include_package_data = True zip_safe = False install_requires = - django >= 1.11 + django >= 2.2.0 requests >= 2.13.0 oauthlib >= 3.0.1 jwcrypto >= 0.4.2