Skip to content

Commit

Permalink
Merge pull request #2 from leibowitz/python3_support
Browse files Browse the repository at this point in the history
Python3 support
  • Loading branch information
leibowitz authored Jul 9, 2018
2 parents 9b1230e + de18095 commit 6458f29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion azure_ad_auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,4 @@ def create_user(self, user_kwargs, payload):

@staticmethod
def username_generator(email):
return urlsafe_b64encode(sha1(email).digest()).rstrip(b'=')
return urlsafe_b64encode(sha1(email.encode('utf-8')).digest()).rstrip(b'=')
7 changes: 6 additions & 1 deletion azure_ad_auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
9 changes: 7 additions & 2 deletions azure_ad_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from urlparse import urlparse


@never_cache
Expand Down Expand Up @@ -44,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():
Expand Down

0 comments on commit 6458f29

Please sign in to comment.