pimutils / vdirsyncer

📇 Synchronize calendars and contacts.

Home Page:https://vdirsyncer.pimutils.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google calendar sync fails with "Missing required parameter: refresh_token"

aketawi opened this issue · comments

Hey, very much enjoying the project so far, however, I've run into an issue with the Google calendar implementation.

Soon after setting up a Google storage, it fails to synchronize with the message:
error: Unknown error occurred for google/username@gmail.com: (invalid_request) Missing required parameter: refresh_token
Removing the token file and re-authorizing fixes the problem, only for it to come back about an hour later.

I've tried redoing the entire configuration from scratch, and was met with the same problem, so I'm stumped now and would greatly appreciate any help.

vdirsyncer --version: vdirsyncer, version 0.19.1
python --version: Python 3.10.10
OS: Arch Linux

config file
[general]
status_path = "~/.vdirsyncer/status/"

[pair google]
a = "google_local"
b = "google_remote"
collections = ["from a", "from b"]

[storage google_local]
type = "filesystem"
path = "~/.calendars/google"
fileext = ".ics"

[storage google_remote]
type = "google_calendar"
token_file = "/path/token"
client_id = "id"
client_secret = "secret"
debug information
Syncing google/username@gmail.com
debug: ====================
debug: PROPFIND https://apidata.googleusercontent.com/caldav/v2/username%40gmail.com/events/
debug: {'User-Agent': '...apps.googleusercontent.com', 'Content-Type': 'application/xml; charset=UTF-8', 'Depth': '1'}
debug: b'<?xml version="1.0" encoding="utf-8" ?>\n            <propfind xmlns="DAV:">\n                <prop>\n                    <resourcetype/>\n                    <getcontenttype/>\n                    <getetag/>\n                </prop>\n            </propfind>\n            '
debug: Sending request...
Syncing google/...@group.calendar.google.com
debug: ====================
debug: PROPFIND https://apidata.googleusercontent.com/caldav/v2/...%40group.calendar.google.com/events/
debug: {'User-Agent': '...apps.googleusercontent.com', 'Content-Type': 'application/xml; charset=UTF-8', 'Depth': '1'}
debug: b'<?xml version="1.0" encoding="utf-8" ?>\n            <propfind xmlns="DAV:">\n                <prop>\n                    <resourcetype/>\n                    <getcontenttype/>\n                    <getetag/>\n                </prop>\n            </propfind>\n            '
debug: Sending request...
debug: 207
debug: <CIMultiDictProxy('Server': 'nginx/1.21.6', 'Date': 'Sun, 19 Mar 2023 10:30:48 GMT', 'Content-Type': 'application/xml; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Set-Cookie': 'PHPSESSID=...; path=/; HttpOnly', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Cache-Control': 'no-store, no-cache, must-revalidate', 'Pragma': 'no-cache', 'X-Sabre-Version': '4.3.0', 'Vary': 'Brief,Prefer', 'DAV': '1, 3, extended-mkcol, access-control, calendarserver-principal-property-search, calendar-access, calendar-proxy, calendar-auto-schedule, calendar-availability, resource-sharing, calendarserver-sharing, addressbook')>
debug: <StreamReader 913 bytes>
error: Unknown error occurred for google/username@gmail.com: (invalid_request) Missing required parameter: refresh_token
error: Use `-vdebug` to see the full traceback.
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/cli/tasks.py", line 72, in sync_collection
debug:     await sync.sync(
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/sync/__init__.py", line 145, in sync
debug:     b_nonempty = await b_info.prepare_new_status()
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/sync/__init__.py", line 48, in prepare_new_status
debug:     async for href, etag in self.storage.list():
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/storage/dav.py", line 860, in list
debug:     async for href, etag in super().list():
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/storage/dav.py", line 677, in list
debug:     response = await self.session.request(
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/storage/google.py", line 68, in request
debug:     return await super().request(method, path, **kwargs)
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/storage/dav.py", line 416, in request
debug:     return await http.request(method, url, session=session, **more)
debug:   File "/usr/lib/python3.10/site-packages/vdirsyncer/http.py", line 132, in request
debug:     response = await session.request(method, url, **kwargs)
debug:   File "/home/tawi/.local/lib/python3.10/site-packages/aiohttp_oauthlib.py", line 519, in _request
debug:     token = await self.refresh_token(
debug:   File "/home/tawi/.local/lib/python3.10/site-packages/aiohttp_oauthlib.py", line 463, in refresh_token
debug:     self.token = self._client.parse_request_body_response(text, scope=self.scope)
debug:   File "/home/tawi/.local/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 427, in parse_request_body_response
debug:     self.token = parse_token_response(body, scope=scope)
debug:   File "/home/tawi/.local/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in parse_token_response
debug:     validate_token_parameters(params)
debug:   File "/home/tawi/.local/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 448, in validate_token_parameters
debug:     raise_from_error(params.get('error'), params)
debug:   File "/home/tawi/.local/lib/python3.10/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 399, in raise_from_error
debug:     raise cls(**kwargs)

The thing that jumps out to me is that the 'Expires' field contains a date from 1981. I've double checked my timezone, time synchronization and everything, so if the issue is in my configuration, I could not pinpoint it.

commented

Can you delete the token_file? It'll prompt you to go through the authentication flow again.

Yep, I did try that and did mention that it will still give the same error about an hour later :v
worst case scenario, I could probably write a script that will delete the token hourly, since the authentication happens without my input after the first time

oh, my bad, didn't mean to close

I have exactly the same issue. After set-up synchonization with Google calendar works fine several times and then failed with (invalid_request) Missing required parameter: refresh_token.

vdirsyncer --version: vdirsyncer, version 0.19.1
python --version: Python 3.10.8
OS: Linux Mint 21.1

I ran into the same issue. I was able to fix it and obtain a refresh token by configuring my OAuth2.0 client ID for vdirsyncer as a Desktop application in the Google cloud console. The vdirsyncer documentation recommends configuring it as a web application, but that didn't work for me. If someone else can confirm that this fixes the issue, maybe the docs should be updated? @WhyNotHugo

@brettferdosi
Confirmed. Currently with "Desktop Application" I have successful syncs for several hours.