|
48 | 48 | from saml2.ident import code, decode
|
49 | 49 | from saml2.sigver import MissingKey
|
50 | 50 | from saml2.s_utils import UnsupportedBinding
|
| 51 | +from saml2.request import AuthnRequest |
51 | 52 | from saml2.response import (
|
52 | 53 | StatusError, StatusAuthnFailed, SignatureError, StatusRequestDenied,
|
53 | 54 | UnsolicitedResponse, StatusNoAuthnContext,
|
@@ -147,26 +148,26 @@ def login(request,
|
147 | 148 |
|
148 | 149 | kwargs = {}
|
149 | 150 | # 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): |
151 | 152 | 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() |
154 | 155 |
|
155 | 156 | # is a embedded wayf needed?
|
156 | 157 | idps = available_idps(conf)
|
157 |
| - if selected_idp is None and len(idps) > 1: |
158 |
| - logger.debug('A discovery process is needed') |
159 |
| - return render(request, wayf_template, { |
160 |
| - 'available_idps': idps.items(), |
161 |
| - 'came_from': came_from, |
162 |
| - }) |
163 |
| - else: |
164 |
| - # is the first one, otherwise next logger message will print None |
165 |
| - if not idps: |
| 158 | + if selected_idp is None: |
| 159 | + if len(idps) > 1: |
| 160 | + logger.debug('A discovery process is needed') |
| 161 | + return render(request, wayf_template, { |
| 162 | + 'available_idps': idps.items(), |
| 163 | + 'came_from': came_from, |
| 164 | + }) |
| 165 | + elif not idps: |
166 | 166 | raise IdPConfigurationMissing(('IdP configuration is missing or '
|
167 | 167 | 'its metadata is expired.'))
|
168 |
| - selected_idp = list(idps.keys())[0] |
169 |
| - |
| 168 | + else: |
| 169 | + selected_idp = list(idps.keys())[0] |
| 170 | + |
170 | 171 | # choose a binding to try first
|
171 | 172 | sign_requests = getattr(conf, '_sp_authn_requests_signed', False)
|
172 | 173 | binding = BINDING_HTTP_POST if sign_requests else BINDING_HTTP_REDIRECT
|
@@ -226,6 +227,9 @@ def login(request,
|
226 | 227 | **kwargs)
|
227 | 228 | try:
|
228 | 229 | 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) |
229 | 233 | saml_request = base64.b64encode(binary_type(request_xml, 'UTF-8')).decode('utf-8')
|
230 | 234 | else:
|
231 | 235 | saml_request = base64.b64encode(binary_type(request_xml))
|
|
0 commit comments