Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-10-13 09:19:35 +02:00
parent 12e184df96
commit 228d924e2c
2 changed files with 8 additions and 3 deletions

View File

@ -67,10 +67,10 @@ def auth():
def refresh(): def refresh():
# refresh token for x amount of time (seconds) # refresh token for x amount of time (seconds)
gauth = GoogleAuth(settings_file="settings.yaml") gauth = GoogleAuth(settings_file="/root/settings.yaml")
try: try:
# Try to load saved client credentials # Try to load saved client credentials
gauth.LoadCredentialsFile("credentials.json") gauth.LoadCredentialsFile("/root/credentials.json")
except pydrive2.auth.InvalidCredentialsError: except pydrive2.auth.InvalidCredentialsError:
print(gauth.GetAuthUrl()) print(gauth.GetAuthUrl())
user_input = input("Please copy this URL into a browser, " user_input = input("Please copy this URL into a browser, "

View File

@ -53,9 +53,14 @@ class GdriveSync(plugins.Plugin):
try: try:
gauth = GoogleAuth(settings_file="/root/settings.yaml") gauth = GoogleAuth(settings_file="/root/settings.yaml")
gauth.LoadCredentialsFile("/root/credentials.json") gauth.LoadCredentialsFile("/root/credentials.json")
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.Authorize() gauth.Authorize()
# Create GoogleDrive instance # Create GoogleDrive instance
self.drive = GoogleDrive(gauth) self.drive = GoogleDrive(gauth)