Skip to content

Commit 1630783

Browse files
committed
SAML bug fixes
* Fix error casting request_xml to bytes when request_xml is an object * Fix _sp_force_authn error when value is missing * Fix allow_create being set to true even when the value is false
1 parent 5c59f6b commit 1630783

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

djangosaml2/views.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from saml2.ident import code, decode
4949
from saml2.sigver import MissingKey
5050
from saml2.s_utils import UnsupportedBinding
51+
from saml2.request import AuthnRequest
5152
from saml2.response import (
5253
StatusError, StatusAuthnFailed, SignatureError, StatusRequestDenied,
5354
UnsolicitedResponse, StatusNoAuthnContext,
@@ -147,10 +148,10 @@ def login(request,
147148

148149
kwargs = {}
149150
# pysaml needs a string otherwise: "cannot serialize True (type bool)"
150-
if getattr(conf, '_sp_force_authn'):
151+
if getattr(conf, '_sp_force_authn', False):
151152
kwargs['force_authn'] = "true"
152-
if getattr(conf, '_sp_allow_create', "false"):
153-
kwargs['allow_create'] = "true"
153+
if hasattr(conf, '_sp_allow_create'):
154+
kwargs['allow_create'] = str(conf._sp_allow_create is True).lower()
154155

155156
# is a embedded wayf needed?
156157
idps = available_idps(conf)
@@ -226,6 +227,9 @@ def login(request,
226227
**kwargs)
227228
try:
228229
if PY3:
230+
if isinstance(request_xml, AuthnRequest):
231+
# request_xml will be an instance of AuthnRequest if the message is not signed
232+
request_xml = str(request_xml)
229233
saml_request = base64.b64encode(binary_type(request_xml, 'UTF-8')).decode('utf-8')
230234
else:
231235
saml_request = base64.b64encode(binary_type(request_xml))

0 commit comments

Comments
 (0)