3636class SAMLIdentityProvider :
3737 """Wrapper around configuration for a SAML Identity provider"""
3838
39- def __init__ (self , name , ** kwargs ) -> None :
39+ def __init__ (self , backend : BaseAuth , name : str , ** kwargs ) -> None :
4040 """Load and parse configuration"""
41+ self .backend = backend
4142 self .name = name
4243 # name should be a slug and must not contain a colon, which
4344 # could conflict with uid prefixing:
@@ -54,7 +55,16 @@ def get_user_permanent_id(self, attributes):
5455 If you want to use the NameID, it's available via
5556 attributes['name_id']
5657 """
57- uid = attributes [self .conf .get ("attr_user_permanent_id" , OID_USERID )]
58+ setting = "attr_user_permanent_id"
59+ key = self .conf .get (setting , OID_USERID )
60+ try :
61+ uid = attributes [key ]
62+ except KeyError as error :
63+ raise AuthMissingParameter (
64+ self .backend ,
65+ f"{ key } (configured by { setting } )" ,
66+ ) from error
67+
5868 if isinstance (uid , list ):
5969 uid = uid [0 ]
6070 return uid
@@ -134,24 +144,6 @@ def saml_config_dict(self):
134144 raise KeyError ("IDP must contain x509cert or x509certMulti" )
135145
136146
137- class DummySAMLIdentityProvider (SAMLIdentityProvider ):
138- """
139- A placeholder IdP used when we must specify something, e.g. when
140- generating SP metadata.
141-
142- If OneLogin_Saml2_Auth is modified to not always require IdP
143- config, this can be removed.
144- """
145-
146- def __init__ (self ) -> None :
147- super ().__init__ (
148- "dummy" ,
149- entity_id = "https://dummy.none/saml2" ,
150- url = "https://dummy.none/SSO" ,
151- x509cert = "" ,
152- )
153-
154-
155147class SAMLAuth (BaseAuth ):
156148 """
157149 PSA Backend that implements SAML 2.0 Service Provider (SP) functionality.
@@ -199,12 +191,12 @@ class SAMLAuth(BaseAuth):
199191 name = "saml"
200192 EXTRA_DATA = []
201193
202- def get_idp (self , idp_name ) :
194+ def get_idp (self , idp_name : str ) -> SAMLIdentityProvider :
203195 """Given the name of an IdP, get a SAMLIdentityProvider instance"""
204196 idp_config = self .setting ("ENABLED_IDPS" )[idp_name ]
205- return SAMLIdentityProvider (idp_name , ** idp_config )
197+ return SAMLIdentityProvider (self , idp_name , ** idp_config )
206198
207- def generate_saml_config (self , idp = None ):
199+ def generate_saml_config (self , idp : SAMLIdentityProvider | None = None ):
208200 """
209201 Generate the configuration required to instantiate OneLogin_Saml2_Auth
210202 """
@@ -265,7 +257,7 @@ def saml_metadata_view(request):
265257 errors = saml_settings .validate_metadata (metadata )
266258 return metadata , errors
267259
268- def _create_saml_auth (self , idp ):
260+ def _create_saml_auth (self , idp : SAMLIdentityProvider ):
269261 """Get an instance of OneLogin_Saml2_Auth"""
270262 config = self .generate_saml_config (idp )
271263 request_info = {
0 commit comments