-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add captcha support #446
base: master
Are you sure you want to change the base?
Add captcha support #446
Conversation
In response to the following build failure: https://travis-ci.org/tdryer/hangups/builds/473486378
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extend the tests in test_auth.py
to cover this?
Google previously announced that they're going to require JavaScript for logins, so at some point in the future this is going to break.
try: | ||
logger.info('Detected captcha, opening image in browser: %s', url) | ||
webbrowser.open(url) | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like webbrowser.open
will just return False
if it can't open a browser.
prompts the user to enter the captcha text. | ||
""" | ||
try: | ||
logger.info('Detected captcha, opening image in browser: %s', url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be better to print this instead of logging it, so the URL appears on the screen in case we can't open a browser.
@@ -319,6 +342,19 @@ def _get_authorization_code(session, credentials_prompt): | |||
password = credentials_prompt.get_password() | |||
browser.submit_form(FORM_SELECTOR, {PASSWORD_SELECTOR: password}) | |||
|
|||
if browser.has_selector(CAPTCHA_SELECTOR): | |||
for image in browser._page.soup.select('div.captcha-img img'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static analysis is complaining about this private attribute access. We could add a Browser.select
method instead.
Context: As explained in #445 I integrated
hangups
in my chat-archive program a few months ago. Back then (August 2018)hangups
worked fine for me, but a few weeks ago the authentication started failing and try as I might I could not get it to work again 🙁.Disclaimer: Initially I had assumed I'd done something stupid when integrating hangups (even though it had worked before) but using
python -m hangups.auth
helped to confirm that my authentication problems had nothing to do with the integration betweenhangups
and chat-archive.Analysis:
_get_authorization_code()
and dumping the response HTML to a temporary file so I could see what was going on 😇.hangups
didn't handle this response it failed to select the mandatory TOTP challenge and as a result the exceptionhangups.auth.GoogleAuthError: Authorization code cookie not found
was raised.Resolution:
hangups
that would at the very least inform the user via logging that authentication was failing due to missing captcha support.pdb
session convinced me that it wouldn't be that hard to actually add support for captcha images instead of just logging a message, because I didn't see another reasonable[1] way to gethangups
to successfully connect again.[1] When I say "reasonable" I'm thinking about the potential audience of my chat-archive program, whom I'm not comfortable asking to open a
pdb
prompt or use the "Web Developer Tools" to extract a cookie from a browser session.Expectation management:
I expect that
hangups
is used in a lot of different contexts (CLI, GUI, headless?) and I guess thewebbrowser.open()
call might be deemed inappropriate, however:The
webbrowser.open()
call is located insideCredentialsPrompt
so that this behavior can easily be overridden by extending.The captcha image URL is logged so that the user can manually open it if the use of
webbrowser.open()
doesn't work.AFAICT when the captcha challenge is presented there was formerly (before this pull request) no way for
hangups
to ever finish successfully, so in that sense backwards compatibility shouldn't be a concern.If there's problems with my current implementation that need to be resolved before this can be merged, feel free to let me know, because I'd love to see this get merged. While this new functionality is likely to be fragile, right now it's definitely an added value for me 🙂.