Skip to content

Commit 4a98ea8

Browse files
committed
Let the setting object to avoid the IdP setting check. required if we want to publish SP SAML Metadata when the IdP data is still not provided. Close #74
1 parent 22596cb commit 4a98ea8

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ The get_sp_metadata will return the metadata signed or not based on the security
496496

497497
Before the XML metadata is exposed, a check takes place to ensure that the info to be provided is valid.
498498

499+
Instead of use the Auth object, you can directly use
500+
```
501+
saml_settings = OneLogin_Saml2_Settings(settings=None, custom_base_path=None, sp_validation_only=True)
502+
```
503+
to get the settings object and with the sp_validation_only=True parameter we will avoid the IdP Settings validation.
504+
499505
***Attribute Consumer Service(ACS)***
500506

501507
This code handles the SAML response that the IdP forwards to the SP through the user's client.
@@ -787,6 +793,8 @@ Configuration of the OneLogin Python Toolkit
787793

788794
* `__init__` Initializes the settings: Sets the paths of the different folders and Loads settings info from settings file or array/object provided.
789795
* ***check_settings*** Checks the settings info.
796+
* ***check_idp_settings*** Checks the IdP settings info.
797+
* ***check_sp_settings*** Checks the SP settings info.
790798
* ***get_errors*** Returns an array with the errors, the array is empty when the settings is ok.
791799
* ***get_sp_metadata*** Gets the SP metadata. The XML representation.
792800
* ***validate_metadata*** Validates an XML SP Metadata.

demo-django/demo/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.template import RequestContext
77

88
from onelogin.saml2.auth import OneLogin_Saml2_Auth
9+
from onelogin.saml2.settings import OneLogin_Saml2_Settings
910
from onelogin.saml2.utils import OneLogin_Saml2_Utils
1011

1112

@@ -100,9 +101,10 @@ def attrs(request):
100101

101102

102103
def metadata(request):
103-
req = prepare_django_request(request)
104-
auth = init_saml_auth(req)
105-
saml_settings = auth.get_settings()
104+
# req = prepare_django_request(request)
105+
# auth = init_saml_auth(req)
106+
# saml_settings = auth.get_settings()
107+
saml_settings = OneLogin_Saml2_Settings(settings=None, custom_base_path=settings.SAML_FOLDER, sp_validation_only=True)
106108
metadata = saml_settings.get_sp_metadata()
107109
errors = saml_settings.validate_metadata(metadata)
108110

src/onelogin/saml2/settings.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class OneLogin_Saml2_Settings(object):
5858
5959
"""
6060

61-
def __init__(self, settings=None, custom_base_path=None):
61+
def __init__(self, settings=None, custom_base_path=None, sp_validation_only=False):
6262
"""
6363
Initializes the settings:
6464
- Sets the paths of the different folders
@@ -70,6 +70,7 @@ def __init__(self, settings=None, custom_base_path=None):
7070
:param custom_base_path: Path where are stored the settings file and the cert folder
7171
:type custom_base_path: string
7272
"""
73+
self.__sp_validation_only = False
7374
self.__paths = {}
7475
self.__strict = False
7576
self.__debug = False
@@ -325,9 +326,10 @@ def check_settings(self, settings):
325326
if not isinstance(settings, dict) or len(settings) == 0:
326327
errors.append('invalid_syntax')
327328
else:
328-
idp_erros = self.check_idp_settings(settings)
329+
if not self.__sp_validation_only:
330+
errors += self.check_idp_settings(settings)
329331
sp_errors = self.check_sp_settings(settings)
330-
errors = idp_erros + sp_errors
332+
errors += sp_errors
331333

332334
return errors
333335

0 commit comments

Comments
 (0)