From 64eddd367c7142ee890f7d16f5e6c35be21e94f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Thu, 5 Sep 2024 20:08:15 -0600 Subject: [PATCH] Support authentication with refresh token + app key --- dropboxdrivefs/core.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dropboxdrivefs/core.py b/dropboxdrivefs/core.py index 23cfe00..6861a78 100644 --- a/dropboxdrivefs/core.py +++ b/dropboxdrivefs/core.py @@ -33,9 +33,17 @@ class DropboxDriveFileSystem(AbstractFileSystem): ``` """ - def __init__(self, token=None, client=None, *args, **storage_options): + def __init__( + self, + token: Optional[str] = None, + client: Optional[str] = None, + app_key: Optional[str] = None, + refresh_token: Optional[str] = None, + *args, + **storage_options, + ): super().__init__(token=token, client=client, *args, **storage_options) - self.connect(token=token, client=client) + self.connect(token=token, client=client, app_key=app_key, refresh_token=refresh_token) def _call(self, _, method="get", path=None, data=None, redirect=True, offset=0, length=None, **kwargs): headers = {"Range": f"bytes={offset}-{offset+length+1}"} @@ -61,13 +69,11 @@ def connect( if client is not None: self.dbx = client elif token is not None: - self.dbx = dropbox.Dropbox( - token, - oauth2_refresh_token=refresh_token, - app_key=app_key, - ) + self.dbx = dropbox.Dropbox(token) + elif app_key is not None and refresh_token is not None: + self.dbx = dropbox.Dropbox(oauth2_refresh_token=refresh_token, app_key=app_key) else: - raise ValueError("You must provide either a token or a dropbox client object.") + raise ValueError("You must provide either a token, an app key and refresh token pair, or a dropbox client object.") self.session = requests.Session() self.session.auth = ("Authorization", self.dbx._oauth2_access_token)