Skip to content

Commit

Permalink
Adding support for mixed auth Slack team login (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin Morelli authored and ErinMorelli committed Sep 10, 2021
1 parent 9bda4e8 commit f17e079
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions parroter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Author : Erin Morelli
Email : [email protected]
License : MIT
Version : 0.1
Version : 0.2
"""

# Future
Expand Down Expand Up @@ -37,7 +37,7 @@
__author__ = 'Erin Morelli'
__email__ = '[email protected]'
__license__ = 'MIT'
__version__ = '0.1'
__version__ = '0.2'

# Disable SSL warnings
urllib3.disable_warnings()
Expand Down Expand Up @@ -193,6 +193,47 @@ def get_form_crumb(self, page):
soup = BeautifulSoup(page.text, self._bs_parser)
return soup.find('input', attrs={'name': 'crumb'})['value']

def get_login_page(self, session):
"""Get the non-OAuth slack team login page.
Args:
session (requests.Session): Requests session object
Returns:
requests.Session: Updated Requests session object
requests.Response: Login page response object
"""
post_regex = r'<form id="signin_form" action="/" method="post"'

# Load initial team landing page
landing = session.get(self.team_url)
landing.raise_for_status()

# Check for presence of login form and return if found
if re.search(post_regex, landing.content):
return (session, landing)

# Attempt to load non-OAuth login page
login = session.get(self.team_url, params={'no_sso': 1})
login.raise_for_status()

# Check for presence of login form and return if found
if re.search(post_regex, login.content):
return (session, login)

# Exit and print error message if login form is not found
print(
' '.join(
[
'ERROR: There was a problem logging in to Slack.',
'OAuth login is not supported at this time.'
]
),
file=sys.stderr
)
sys.exit(1)

def start_session(self):
"""Login to Slack to start browsing session.
Expand All @@ -203,8 +244,7 @@ def start_session(self):
session = requests.Session()

# Load login page
login_page = session.get(self.team_url)
login_page.raise_for_status()
(session, login_page) = self.get_login_page(session)

# Get login crumb
login_crumb = self.get_form_crumb(login_page)
Expand Down

0 comments on commit f17e079

Please sign in to comment.