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

invalid_grant: Bad Request #298

Open
aspiers opened this issue Feb 23, 2025 · 1 comment
Open

invalid_grant: Bad Request #298

aspiers opened this issue Feb 23, 2025 · 1 comment

Comments

@aspiers
Copy link
Contributor

aspiers commented Feb 23, 2025

I had lieer working great a few months ago using my own Google Cloud project and OAuth 2.0 Client ID, then stopped using it for no good reason. I just came back to it now and started seeing this:

$ gmi sync -v
Traceback (most recent call last):
  File "/home/adam/.local/bin/gmi", line 24, in <module>
    g.main ()
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/lieer/gmailieer.py", line 419, in main
    args.func(args)
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/lieer/gmailieer.py", line 499, in sync
    self.remote.get_labels()
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/lieer/remote.py", line 140, in func_wrap
    self.authorize()
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/lieer/remote.py", line 497, in authorize
    self.credentials = self.__get_credentials__()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/lieer/remote.py", line 552, in __get_credentials__
    credentials.refresh(Request())
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/google/oauth2/credentials.py", line 409, in refresh
    ) = reauth.refresh_grant(
        ^^^^^^^^^^^^^^^^^^^^^
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/google/oauth2/reauth.py", line 366, in refresh_grant
    _client._handle_error_response(response_data, retryable_error)
  File "/home/adam/.local/share/pipx/venvs/lieer/lib64/python3.11/site-packages/google/oauth2/_client.py", line 68, in _handle_error_response
    raise exceptions.RefreshError(
google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})

I got it working after doing both of the following, although it's possible that only one of them was required and I'm not sure which:

  1. Adding my gmail account as a test user to the GCP project
  2. Running gmi auth -v -f and (re-?)agreeing to give the project the required permissions to my gmail account

I had initially tried creating a new OAuth 2.0 Client ID in the same project and then running gmi auth -v -c client_secret_*.apps.googleusercontent.com.json but this didn't work, so then I tried replacing the -c switch with -f and it worked. I'm not sure if this has resulted in using the new client ID or not.

Anyway, hope this helps someone. It would be great if this was documented on the website.

@impaktor
Copy link

I think this fixed my issue as well.

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

No branches or pull requests

2 participants