Skip to content
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

Cant make API token. #269

Closed
naechin91004 opened this issue Oct 4, 2016 · 6 comments
Closed

Cant make API token. #269

naechin91004 opened this issue Oct 4, 2016 · 6 comments

Comments

@naechin91004
Copy link

naechin91004 commented Oct 4, 2016

Hello.

Today cant not run hangups.
I think google something change about api token.

Below URL didnt work.
https://accounts.google.com/o/oauth2/auth?redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&client_id=936475272427.apps.googleusercontent.com&response_type=code&scope=https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthLogin

How can make token?
PLZ help me.

@StuntsPT
Copy link
Contributor

StuntsPT commented Oct 4, 2016

Are you running the latest version (0.4.1)?

@dstelzer
Copy link

dstelzer commented Oct 4, 2016

Pip install --upgrade hangups and see if that fixes it. 0.4.1 uses a different authentication mechanism with a hardcoded API key.

@djacobow
Copy link

Okay, I've been working through this issue, following what I saw in issue #260. I think faking the browser and login page is not going to work as a general solution. In my case, my organization uses Google's facility for shunting the user to/from our own Shibboleth, so I see a different login page.

I don't see a way to get a token right now, other than to follow @dequis original video and copy the token. But for that to work, we need to go back to the old login code, or at least have a way to run it.

Really pretty stumped here.

@tdryer
Copy link
Owner

tdryer commented Oct 19, 2016

If you can get the token manually, you can create the refresh_token.txt file yourself and get hangups to use it.

@djacobow
Copy link

OK, so after some fiddling I worked this out -- sorry, I'm no oauth expert, but maybe some others looking at this thread aren't, either.

The token returned in the cookie from:

https://accounts.google.com/o/oauth2/programmatic_auth?client_id=936475272427.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthLogin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email

is an auth token, not a refresh token. You can't just paste it into refresh_token.txt.

What I did was was short circuit _get_authorization_code in auth.py and set the authorization_code directly to the value returned in the programmatic_auth page. The code then goes through the rest of _auth_with_code and writes a new refresh token that works.

It might be worth adding a path to the code where it asks for your credentials as usual and tries to fake being a browser, and if that fails, then it just prints out the link + instructions for you to "do it yourself in a real browser", finally prompting you for the auth code.

@n3k0lai
Copy link

n3k0lai commented Nov 3, 2016

I tried to install Pickups tonight, and I am getting a hangups error which I think is related to this issue. I am not quite a Python guru, so I hope this error log helps the resolution of this:

INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): accounts.google.com
Sign in with your Google account:
Email: <email>
Password: <password>
Traceback (most recent call last):
  File "/usr/lib64/python3.4/site-packages/hangups/auth.py", line 133, in get_auth
    raise GoogleAuthError("Refresh token not found")
hangups.auth.GoogleAuthError: Refresh token not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.4/site-packages/hangups/auth.py", line 248, in _get_authorization_code
    return browser.get_cookie('oauth_code')
  File "/usr/lib64/python3.4/site-packages/hangups/auth.py", line 211, in get_cookie
    return self._session.cookies[name]
  File "/usr/lib64/python3.4/site-packages/requests/cookies.py", line 282, in __getitem__
    return self._find_no_duplicates(name)
  File "/usr/lib64/python3.4/site-packages/requests/cookies.py", line 340, in _find_no_duplicates
    raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='oauth_code', domain=None, path=None"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/silent/pickups/pickups/__main__.py", line 16, in <module>
    cookies = hangups.auth.get_auth_stdin(default_cookies_path)
  File "/usr/lib64/python3.4/site-packages/hangups/auth.py", line 65, in get_auth_stdin
    return get_auth(CredentialsPrompt(), refresh_token_cache)
  File "/usr/lib64/python3.4/site-packages/hangups/auth.py", line 139, in get_auth
    session, credentials_prompt
  File "/usr/lib64/python3.4/site-packages/hangups/auth.py", line 250, in _get_authorization_code
    raise GoogleAuthError('Authorization code cookie not found')
hangups.auth.GoogleAuthError: Authorization code cookie not found

I am running the most recent version of hangups on a VPS running gentoo, and I can provide more information as requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants