Files
Foundry/overlays/vdirsyncer-fixed-oauth-token.patch

95 lines
3.0 KiB
Diff

diff --git a/docs/config.rst b/docs/config.rst
index a351f5c..c8437c1 100644
--- a/docs/config.rst
+++ b/docs/config.rst
@@ -314,6 +314,10 @@ The ``token_file`` parameter should be a path to a file where vdirsyncer can
later store authentication-related data. You do not need to create the file
itself or write anything to it.
+Alternatively, you can specify the oauth access token directly through the
+``access_token`` parameter. This is useful when used together with `oama
+<https://github.com/pdobsan/oama>` or similar solutions.
+
.. [googleterms] See `ToS <https://developers.google.com/terms/?hl=th>`_,
section "Confidential Matters".
@@ -334,6 +338,7 @@ itself or write anything to it.
token_file = "..."
client_id = "..."
client_secret = "..."
+ #access_token = "..."
#start_date = null
#end_date = null
#item_types = []
diff --git a/vdirsyncer/storage/google.py b/vdirsyncer/storage/google.py
index 3109213..fb22b00 100644
--- a/vdirsyncer/storage/google.py
+++ b/vdirsyncer/storage/google.py
@@ -13,6 +13,7 @@ import aiohttp
import click
from .. import exceptions
+from ..http import USERAGENT
from ..utils import atomic_write
from ..utils import checkdir
from ..utils import expand_path
@@ -39,10 +40,12 @@ except ImportError:
class GoogleSession(dav.DAVSession):
def __init__(
self,
- token_file,
- client_id,
- client_secret,
+ token_file=None,
+ client_id=None,
+ client_secret=None,
+ access_token=None,
url=None,
+ useragent=USERAGENT,
*,
connector: aiohttp.BaseConnector,
):
@@ -53,14 +56,17 @@ class GoogleSession(dav.DAVSession):
if url is not None:
self.url = url
- self.useragent = client_id
+ self.useragent = client_id or useragent
self._settings = {}
self.connector = connector
- self._token_file = Path(expand_path(token_file))
+ if token_file is not None:
+ self._token_file = Path(expand_path(token_file))
+
self._client_id = client_id
self._client_secret = client_secret
- self._token = None
+ if access_token:
+ self._token = {"access_token": access_token}
self._redirect_uri = None
async def request(self, method, path, **kwargs):
@@ -184,9 +190,9 @@ class GoogleCalendarStorage(dav.CalDAVStorage):
def __init__(
self,
- token_file,
- client_id,
- client_secret,
+ token_file=None,
+ client_id=None,
+ client_secret=None,
start_date=None,
end_date=None,
item_types=(),
@@ -229,7 +235,7 @@ class GoogleContactsStorage(dav.CardDAVStorage):
storage_name = "google_contacts"
- def __init__(self, token_file, client_id, client_secret, **kwargs):
+ def __init__(self, token_file=None, client_id=None, client_secret=None, **kwargs):
if not kwargs.get("collection"):
raise exceptions.CollectionRequired