From eab3f1c222d0f16b688dd333c2fdeb8bbff7edcd Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Sat, 14 Oct 2023 07:43:34 +0200 Subject: [PATCH] v2.4.7 Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/gdrivesync.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pwnagotchi/plugins/default/gdrivesync.py b/pwnagotchi/plugins/default/gdrivesync.py index 10c5834e..faa46d5e 100644 --- a/pwnagotchi/plugins/default/gdrivesync.py +++ b/pwnagotchi/plugins/default/gdrivesync.py @@ -7,7 +7,6 @@ import pwnagotchi import pydrive2 from pydrive2.auth import GoogleAuth from pydrive2.drive import GoogleDrive -from pwnagotchi.google import cmd as google_cmd class GdriveSync(plugins.Plugin): @@ -46,8 +45,14 @@ class GdriveSync(plugins.Plugin): try: gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth.LoadCredentialsFile("/root/credentials.json") - gauth.Authorize() + if gauth.credentials is None: + # Authenticate if they're not there + gauth.LocalWebserverAuth() + elif gauth.access_token_expired: + # Refresh them if expired + gauth.Refresh() gauth.SaveCredentialsFile("/root/credentials.json") + gauth.Authorize() # Create GoogleDrive instance self.drive = GoogleDrive(gauth) @@ -109,7 +114,7 @@ class GdriveSync(plugins.Plugin): for file in file_list: if file['title'] == folder_name: return file['id'] - return None + return None def on_unload(self, ui): logging.info("[gdrivesync] unloaded")