Skip to content

Commit cc8663d

Browse files
committed
Add option to set preferred logout request binding
1 parent 5c5f77b commit cc8663d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ If you want to allow several authentication mechanisms in your project
110110
you should set the LOGIN_URL option to another view and put a link in such
111111
view to the ``/saml2/login/`` view.
112112

113+
Preferred Logout binding
114+
-----------------
115+
Use the following setting to choose your preferred binding for SP initiated logout requests::
116+
117+
SAML_LOGOUT_REQUEST_PREFERRED_BINDING
118+
119+
For example::
120+
121+
import saml2
122+
SAML_LOGOUT_REQUEST_PREFERRED_BINDING = saml2.BINDING_HTTP_POST
113123

114124
Changes in the urls.py file
115125
---------------------------

djangosaml2/overrides.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import logging
2+
3+
import saml2.client
4+
from django.conf import settings
5+
6+
logger = logging.getLogger('djangosaml2')
7+
8+
9+
class Saml2Client(saml2.client.Saml2Client):
10+
"""
11+
Custom Saml2Client that adds a choice of preference for binding used with
12+
SAML Logout Requests. The preferred binding can be configured via
13+
SAML_LOGOUT_REQUEST_PREFERRED_BINDING settings variable.
14+
(Original Saml2Client always prefers SOAP, so it is always used if declared
15+
in remote metadata); but doesn't actually work and causes crashes.
16+
"""
17+
def do_logout(self, *args, **kwargs):
18+
if not kwargs.get('expected_binding'):
19+
try:
20+
kwargs['expected_binding'] = settings.SAML_LOGOUT_REQUEST_PREFERRED_BINDING
21+
except AttributeError:
22+
logger.warning('SAML_LOGOUT_REQUEST_PREFERRED_BINDING setting is'
23+
' not defined. Default binding will be used.')
24+
return super(Saml2Client, self).do_logout(*args, **kwargs)

djangosaml2/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from django.views.decorators.csrf import csrf_exempt
3939

4040
from saml2 import BINDING_HTTP_REDIRECT, BINDING_HTTP_POST
41-
from saml2.client import Saml2Client
4241
from saml2.metadata import entity_descriptor
4342
from saml2.ident import code, decode
4443
from saml2.sigver import MissingKey
@@ -50,6 +49,7 @@
5049
from djangosaml2.cache import IdentityCache, OutstandingQueriesCache
5150
from djangosaml2.cache import StateCache
5251
from djangosaml2.conf import get_config
52+
from djangosaml2.overrides import Saml2Client
5353
from djangosaml2.signals import post_authenticated
5454
from djangosaml2.utils import fail_acs_response, get_custom_setting, available_idps, get_location, get_idp_sso_supported_bindings
5555

0 commit comments

Comments
 (0)