@@ -71,6 +71,10 @@ do to make sure it is compatible with your Django version and environment.
7171 Python users need to ``pip install djangosaml2[test] `` in order to run the
7272 tests.
7373
74+ Add the SAML Session Middleware as follow, this is needed for SameSite Cookies::
75+
76+ MIDDLEWARE.append('djangosaml2.middleware.SamlSessionMiddleware')
77+
7478Then you have to add the ``djangosaml2.backends.Saml2Backend ``
7579authentication backend to the list of authentications backends.
7680By default only the ModelBackend included in Django is configured.
@@ -106,9 +110,6 @@ If you want to allow several authentication mechanisms in your project
106110you should set the LOGIN_URL option to another view and put a link in such
107111view to the ``/saml2/login/ `` view.
108112
109- Add the SAML Session Middleware as follow::
110-
111- MIDDLEWARE.append('djangosaml2.middleware.SamlSessionMiddleware')
112113
113114Handling Post-Login Redirects
114115-----------------------------
@@ -138,7 +139,7 @@ For example::
138139
139140 import saml2
140141 SAML_LOGOUT_REQUEST_PREFERRED_BINDING = saml2.BINDING_HTTP_POST
141-
142+
142143Signed Logout Request
143144------------------------
144145Idp's like Okta require a signed logout response to validate and logout a user. Here's a sample config with all required SP/IDP settings::
@@ -176,75 +177,6 @@ the path to that file.
176177In djangosaml2 you just put the same information in the Django
177178settings.py file under the SAML_CONFIG option.
178179
179- Okta settings to configure on your Idp's SAML app advanced settings::
180-
181- Single Logout URL: http://localhost:8000/saml2/ls/post/
182- SP Issuer : http://localhost:8000/saml2/metadata/
183-
184- Okta sample configuration for setting up an Okta SSO with Django::
185-
186- 'service': {
187- # we are just a lonely SP
188- 'sp': {
189- 'name': 'XXX',
190- 'allow_unsolicited': True,
191- 'want_assertions_signed': True, # assertion signing (default=True)
192- 'want_response_signed': True,
193- "want_assertions_or_response_signed": True, # is response signing required
194- 'name_id_format': NAMEID_FORMAT_UNSPECIFIED,
195-
196- # Must for signed logout requests
197- "logout_requests_signed": True,
198- 'endpoints': {
199- # url and binding to the assetion consumer service view
200- # do not change the binding or service name
201- 'assertion_consumer_service': [
202- ('http://localhost:8000/saml2/acs/',
203- saml2.BINDING_HTTP_POST),
204- ],
205- # url and binding to the single logout service view
206- # do not change the binding or service name
207- 'single_logout_service': [
208- # ('http://localhost:8000/saml2/ls/',
209- # saml2.BINDING_HTTP_REDIRECT),
210- ('http://localhost:8000/saml2/ls/post/',
211- saml2.BINDING_HTTP_POST),
212- ],
213- },
214- # Mandates that the identity provider MUST authenticate the
215- # presenter directly rather than rely on a previous security context.
216- 'force_authn': False,
217-
218- "allow_unsolicited": True,
219-
220- # Enable AllowCreate in NameIDPolicy.
221- 'name_id_format_allow_create': False,
222-
223- # attributes that this project need to identify a user
224- 'required_attributes': ['email'],
225-
226- # in this section the list of IdPs we talk to are defined
227- 'idp': {
228- # we do not need a WAYF service since there is
229- # only an IdP defined here. This IdP should be
230- # present in our metadata
231-
232- # the keys of this dictionary are entity ids
233- 'https://xxx.okta.com/app/XXXXXXXXXX/sso/saml/metadata': {
234- # Okta only uses HTTP_POST disable this
235- # 'single_sign_on_service': {
236- # saml2.BINDING_HTTP_REDIRECT: 'https://xxx.okta.com/app/APPNAME/xxxxxxxxx/sso/saml',
237- # },
238- 'single_logout_service': {
239- saml2.BINDING_HTTP_POST: 'https://xxx.okta.com/app/APPNAME/xxxxxxxxxx/slo/saml',
240- },
241- },
242- },
243-
244- },
245- },
246-
247-
248180We will see a typical configuration for protecting a Django project::
249181
250182 from os import path
@@ -267,10 +199,10 @@ We will see a typical configuration for protecting a Django project::
267199 'sp' : {
268200 'name': 'Federated Django sample SP',
269201 'name_id_format': saml2.saml.NAMEID_FORMAT_PERSISTENT,
270-
202+
271203 # For Okta add signed logout requets. Enable this:
272204 # "logout_requests_signed": True,
273-
205+
274206 'endpoints': {
275207 # url and binding to the assetion consumer service view
276208 # do not change the binding or service name
@@ -619,6 +551,78 @@ filter like this::
619551 'class' => 'core:AttributeMap', 'name2oid'
620552 ),
621553
554+ Okta federation
555+ ===============
556+
557+ Okta settings to configure on your Idp's SAML app advanced settings::
558+
559+ Single Logout URL: http://localhost:8000/saml2/ls/post/
560+ SP Issuer : http://localhost:8000/saml2/metadata/
561+
562+ Okta sample configuration for setting up an Okta SSO with Django::
563+
564+ 'service': {
565+ # we are just a lonely SP
566+ 'sp': {
567+ 'name': 'XXX',
568+ 'allow_unsolicited': True,
569+ 'want_assertions_signed': True, # assertion signing (default=True)
570+ 'want_response_signed': True,
571+ "want_assertions_or_response_signed": True, # is response signing required
572+ 'name_id_format': NAMEID_FORMAT_UNSPECIFIED,
573+
574+ # Must for signed logout requests
575+ "logout_requests_signed": True,
576+ 'endpoints': {
577+ # url and binding to the assetion consumer service view
578+ # do not change the binding or service name
579+ 'assertion_consumer_service': [
580+ ('http://localhost:8000/saml2/acs/',
581+ saml2.BINDING_HTTP_POST),
582+ ],
583+ # url and binding to the single logout service view
584+ # do not change the binding or service name
585+ 'single_logout_service': [
586+ # ('http://localhost:8000/saml2/ls/',
587+ # saml2.BINDING_HTTP_REDIRECT),
588+ ('http://localhost:8000/saml2/ls/post/',
589+ saml2.BINDING_HTTP_POST),
590+ ],
591+ },
592+ # Mandates that the identity provider MUST authenticate the
593+ # presenter directly rather than rely on a previous security context.
594+ 'force_authn': False,
595+
596+ "allow_unsolicited": True,
597+
598+ # Enable AllowCreate in NameIDPolicy.
599+ 'name_id_format_allow_create': False,
600+
601+ # attributes that this project need to identify a user
602+ 'required_attributes': ['email'],
603+
604+ # in this section the list of IdPs we talk to are defined
605+ 'idp': {
606+ # we do not need a WAYF service since there is
607+ # only an IdP defined here. This IdP should be
608+ # present in our metadata
609+
610+ # the keys of this dictionary are entity ids
611+ 'https://xxx.okta.com/app/XXXXXXXXXX/sso/saml/metadata': {
612+ # Okta only uses HTTP_POST disable this
613+ # 'single_sign_on_service': {
614+ # saml2.BINDING_HTTP_REDIRECT: 'https://xxx.okta.com/app/APPNAME/xxxxxxxxx/sso/saml',
615+ # },
616+ 'single_logout_service': {
617+ saml2.BINDING_HTTP_POST: 'https://xxx.okta.com/app/APPNAME/xxxxxxxxxx/slo/saml',
618+ },
619+ },
620+ },
621+
622+ },
623+ },
624+
625+
622626Testing
623627=======
624628
0 commit comments