From 4bbf911d0e81be83d4aa1598170ec0b895087837 Mon Sep 17 00:00:00 2001 From: Gianni Moschini Date: Sat, 3 Mar 2018 00:16:45 +0000 Subject: [PATCH 1/3] Update import to support python3 --- azure_ad_auth/utils.py | 7 ++++++- azure_ad_auth/views.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/azure_ad_auth/utils.py b/azure_ad_auth/utils.py index 9127a8b..a03957d 100644 --- a/azure_ad_auth/utils.py +++ b/azure_ad_auth/utils.py @@ -5,7 +5,12 @@ import jwt from lxml import etree import requests -from urllib import urlencode +try: + # Python 3 + from urllib.parse import urlencode +except ImportError: + # Python 2 + from urllib import urlencode AUTHORITY = getattr(settings, 'AAD_AUTHORITY', 'https://login.microsoftonline.com') diff --git a/azure_ad_auth/views.py b/azure_ad_auth/views.py index 5af326e..a180d63 100644 --- a/azure_ad_auth/views.py +++ b/azure_ad_auth/views.py @@ -5,8 +5,13 @@ from django.http import HttpResponseRedirect from django.views.decorators.csrf import csrf_exempt from django.views.decorators.cache import never_cache -import urlparse import uuid +try: + # Python 3 + from urllib.parse import urlparse +except ImportError: + # Python 2 + import urlparse @never_cache From 99b5eb66fbd2f04c7f8bbac9fcf904331b965874 Mon Sep 17 00:00:00 2001 From: Gianni Moschini Date: Sat, 3 Mar 2018 00:17:07 +0000 Subject: [PATCH 2/3] Fix email argument not encoded --- azure_ad_auth/backends.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure_ad_auth/backends.py b/azure_ad_auth/backends.py index 443c709..eb25fad 100644 --- a/azure_ad_auth/backends.py +++ b/azure_ad_auth/backends.py @@ -69,4 +69,4 @@ def create_user(self, email): @staticmethod def username_generator(email): - return urlsafe_b64encode(sha1(email).digest()).rstrip(b'=') + return urlsafe_b64encode(sha1(email.encode('utf-8')).digest()).rstrip(b'=') From de180955df119c4bf5047cfd09479a650de4e59b Mon Sep 17 00:00:00 2001 From: Gianni Moschini Date: Sat, 3 Mar 2018 00:50:22 +0000 Subject: [PATCH 3/3] Fix import --- azure_ad_auth/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure_ad_auth/views.py b/azure_ad_auth/views.py index a180d63..0c02ceb 100644 --- a/azure_ad_auth/views.py +++ b/azure_ad_auth/views.py @@ -11,7 +11,7 @@ from urllib.parse import urlparse except ImportError: # Python 2 - import urlparse + from urlparse import urlparse @never_cache @@ -49,7 +49,7 @@ def complete(request): def get_login_success_url(request): redirect_to = request.GET.get(REDIRECT_FIELD_NAME, '') - netloc = urlparse.urlparse(redirect_to)[1] + netloc = urlparse(redirect_to)[1] if not redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL elif netloc and netloc != request.get_host():