-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for mixed auth Slack team login (#3)
- Loading branch information
1 parent
9bda4e8
commit f17e079
Showing
1 changed file
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
Author : Erin Morelli | ||
Email : [email protected] | ||
License : MIT | ||
Version : 0.1 | ||
Version : 0.2 | ||
""" | ||
|
||
# Future | ||
|
@@ -37,7 +37,7 @@ | |
__author__ = 'Erin Morelli' | ||
__email__ = '[email protected]' | ||
__license__ = 'MIT' | ||
__version__ = '0.1' | ||
__version__ = '0.2' | ||
|
||
# Disable SSL warnings | ||
urllib3.disable_warnings() | ||
|
@@ -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. | ||
|
@@ -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) | ||
|