Skip to content

Commit 41b1e4c

Browse files
authored
Merge pull request #105 from charn/fix-broken-python2
Fix library broken for Python 2
2 parents 2aa63a7 + 6dcbf33 commit 41b1e4c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

djangosaml2/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from django.views.decorators.http import require_POST
3838
from django.shortcuts import render
3939
from django.template import TemplateDoesNotExist
40-
from django.utils.six import text_type, binary_type
40+
from django.utils.six import text_type, binary_type, PY3
4141
from django.views.decorators.csrf import csrf_exempt
4242

4343
from saml2 import BINDING_HTTP_REDIRECT, BINDING_HTTP_POST
@@ -202,10 +202,15 @@ def login(request,
202202
location,
203203
binding=binding)
204204
try:
205+
if PY3:
206+
saml_request = base64.b64encode(binary_type(request_xml, 'UTF-8'))
207+
else:
208+
saml_request = base64.b64encode(binary_type(request_xml))
209+
205210
http_response = render(request, post_binding_form_template, {
206211
'target_url': location,
207212
'params': {
208-
'SAMLRequest': base64.b64encode(binary_type(request_xml, 'UTF-8')),
213+
'SAMLRequest': saml_request,
209214
'RelayState': came_from,
210215
},
211216
})

0 commit comments

Comments
 (0)