Skip to content

Commit

Permalink
Fix for awslabs#11 by allowing multiple field names to choose from.
Browse files Browse the repository at this point in the history
  • Loading branch information
groboclown committed Aug 5, 2019
1 parent a216e70 commit 692189e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions awsprocesscreds/saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def retrieve_saml_assertion(self, config):


class GenericFormsBasedAuthenticator(SAMLAuthenticator):
USERNAME_FIELD = 'username'
PASSWORD_FIELD = 'password'
USERNAME_FIELDS = ('username',)
PASSWORD_FIELDS = ('password',)

_ERROR_BAD_RESPONSE = (
'Received a non-200 response (%s) when making a request to: %s'
Expand Down Expand Up @@ -175,13 +175,15 @@ def _parse_form_from_html(self, html):

def _fill_in_form_values(self, config, form_data):
username = config['saml_username']
if self.USERNAME_FIELD not in form_data:
username_field = set(self.USERNAME_FIELDS).intersection(form_data.keys())
if not username_field:
raise SAMLError(
self._ERROR_MISSING_FORM_FIELD % self.USERNAME_FIELD)
self._ERROR_MISSING_FORM_FIELD % self.USERNAME_FIELDS)
else:
form_data[self.USERNAME_FIELD] = username
if self.PASSWORD_FIELD in form_data:
form_data[self.PASSWORD_FIELD] = self._password_prompter(
form_data[username_field.pop()] = username
password_field = set(self.PASSWORD_FIELDS).intersection(form_data.keys())
if password_field:
form_data[password_field.pop()] = self._password_prompter(
"Password: ")

def _send_form_post(self, login_url, form_data):
Expand Down Expand Up @@ -255,8 +257,8 @@ def is_suitable(self, config):


class ADFSFormsBasedAuthenticator(GenericFormsBasedAuthenticator):
USERNAME_FIELD = 'ctl00$ContentPlaceHolder1$UsernameTextBox'
PASSWORD_FIELD = 'ctl00$ContentPlaceHolder1$PasswordTextBox'
USERNAME_FIELDS = ('ctl00$ContentPlaceHolder1$UsernameTextBox', 'UserName',)
PASSWORD_FIELDS = ('ctl00$ContentPlaceHolder1$PasswordTextBox', 'Password',)

def is_suitable(self, config):
return (config.get('saml_authentication_type') == 'form' and
Expand Down

0 comments on commit 692189e

Please sign in to comment.