@@ -57,8 +57,8 @@ def retrieve_saml_assertion(self, config):
57
57
58
58
59
59
class GenericFormsBasedAuthenticator (SAMLAuthenticator ):
60
- USERNAME_FIELD = 'username'
61
- PASSWORD_FIELD = 'password'
60
+ USERNAME_FIELDS = ( 'username' ,)
61
+ PASSWORD_FIELDS = ( 'password' ,)
62
62
63
63
_ERROR_BAD_RESPONSE = (
64
64
'Received a non-200 response (%s) when making a request to: %s'
@@ -175,13 +175,19 @@ def _parse_form_from_html(self, html):
175
175
176
176
def _fill_in_form_values (self , config , form_data ):
177
177
username = config ['saml_username' ]
178
- if self .USERNAME_FIELD not in form_data :
178
+ username_field = set (self .USERNAME_FIELDS ).intersection (
179
+ form_data .keys ()
180
+ )
181
+ if not username_field :
179
182
raise SAMLError (
180
- self ._ERROR_MISSING_FORM_FIELD % self .USERNAME_FIELD )
181
- else :
182
- form_data [self .USERNAME_FIELD ] = username
183
- if self .PASSWORD_FIELD in form_data :
184
- form_data [self .PASSWORD_FIELD ] = self ._password_prompter (
183
+ self ._ERROR_MISSING_FORM_FIELD % self .USERNAME_FIELDS )
184
+ form_data [username_field .pop ()] = username
185
+
186
+ password_field = set (self .PASSWORD_FIELDS ).intersection (
187
+ form_data .keys ()
188
+ )
189
+ if password_field :
190
+ form_data [password_field .pop ()] = self ._password_prompter (
185
191
"Password: " )
186
192
187
193
def _send_form_post (self , login_url , form_data ):
@@ -250,17 +256,27 @@ def retrieve_saml_assertion(self, config):
250
256
return r
251
257
252
258
def is_suitable (self , config ):
253
- return (config .get ('saml_authentication_type' ) == 'form' and
254
- config .get ('saml_provider' ) == 'okta' )
259
+ return (
260
+ config .get ('saml_authentication_type' ) == 'form'
261
+ and config .get ('saml_provider' ) == 'okta'
262
+ )
255
263
256
264
257
265
class ADFSFormsBasedAuthenticator (GenericFormsBasedAuthenticator ):
258
- USERNAME_FIELD = 'ctl00$ContentPlaceHolder1$UsernameTextBox'
259
- PASSWORD_FIELD = 'ctl00$ContentPlaceHolder1$PasswordTextBox'
266
+ USERNAME_FIELDS = (
267
+ 'ctl00$ContentPlaceHolder1$UsernameTextBox' ,
268
+ 'UserName' ,
269
+ )
270
+ PASSWORD_FIELDS = (
271
+ 'ctl00$ContentPlaceHolder1$PasswordTextBox' ,
272
+ 'Password' ,
273
+ )
260
274
261
275
def is_suitable (self , config ):
262
- return (config .get ('saml_authentication_type' ) == 'form' and
263
- config .get ('saml_provider' ) == 'adfs' )
276
+ return (
277
+ config .get ('saml_authentication_type' ) == 'form'
278
+ and config .get ('saml_provider' ) == 'adfs'
279
+ )
264
280
265
281
266
282
class FormParser (six .moves .html_parser .HTMLParser ):
0 commit comments