Skip to content

Commit

Permalink
Support authentication with refresh token + app key
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 6, 2024
1 parent b863f77 commit 64eddd3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions dropboxdrivefs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"}
Expand All @@ -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)
Expand Down

0 comments on commit 64eddd3

Please sign in to comment.