|
13 | 13 | # See the License for the specific language governing permissions and
|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
| 16 | +import base64 |
16 | 17 | import logging
|
17 | 18 |
|
18 | 19 | try:
|
19 | 20 | from xml.etree import ElementTree
|
20 | 21 | except ImportError:
|
21 | 22 | from elementtree import ElementTree
|
22 |
| -from defusedxml.common import (DTDForbidden, EntitiesForbidden, |
23 |
| - ExternalReferenceForbidden) |
24 | 23 |
|
25 | 24 | from django.conf import settings
|
26 | 25 | from django.contrib import auth
|
@@ -54,8 +53,7 @@ def csrf_exempt(view_func):
|
54 | 53 | from djangosaml2.cache import StateCache
|
55 | 54 | from djangosaml2.conf import get_config
|
56 | 55 | from djangosaml2.signals import post_authenticated
|
57 |
| -from djangosaml2.utils import get_custom_setting, available_idps, get_location, \ |
58 |
| - get_hidden_form_inputs |
| 56 | +from djangosaml2.utils import get_custom_setting, available_idps, get_location |
59 | 57 |
|
60 | 58 |
|
61 | 59 | logger = logging.getLogger('djangosaml2')
|
@@ -177,17 +175,20 @@ def login(request,
|
177 | 175 | return HttpResponseRedirect(get_location(result))
|
178 | 176 | elif binding == BINDING_HTTP_POST:
|
179 | 177 | if not post_binding_form_template:
|
| 178 | + # use the html provided by pysaml2 |
180 | 179 | return HttpResponse(result['data'])
|
181 |
| - try: |
182 |
| - params = get_hidden_form_inputs(result['data'][3]) |
| 180 | + else: |
| 181 | + # manually get request XML to build our own template |
| 182 | + request_id, request_xml = client.create_authn_request( |
| 183 | + client._sso_location(selected_idp, binding), |
| 184 | + binding=binding) |
183 | 185 | return render(request, post_binding_form_template, {
|
184 |
| - 'target_url': result['url'], |
185 |
| - 'params': params, |
186 |
| - }) |
187 |
| - except (DTDForbidden, EntitiesForbidden, ExternalReferenceForbidden): |
188 |
| - raise PermissionDenied |
189 |
| - except TemplateDoesNotExist: |
190 |
| - return HttpResponse(result['data']) |
| 186 | + 'target_url': result['url'], |
| 187 | + 'params': { |
| 188 | + 'SAMLRequest': base64.b64encode(request_xml), |
| 189 | + 'RelayState': came_from, |
| 190 | + }, |
| 191 | + }) |
191 | 192 | else:
|
192 | 193 | raise NotImplementedError('Unsupported binding: %s', binding)
|
193 | 194 |
|
|
0 commit comments