def authenticate_and_authorize(options, settings_file=None, method="local"): gauth = GoogleAuth(settings_file=settings_file) gauth.LoadCredentials() if gauth.credentials is not None: raise RuntimeError( "Error: credentials found at %s and it's already authenticated; skipping..." % gauth.settings.get("save_credentials_file")) if method == "local": gauth.LocalWebserverAuth(host_name=options.hostname, port_numbers=options.ports) elif method == "command_line": gauth.CommandLineAuth() else: raise ValueError( "Error: received --method=%s, but --method can only be either 'local' or 'command_line'." % method) if gauth: print() print("Finished authentication and authorizion.") print( "Please configure google drive client with gdrive-config if you have not done so yet." ) print("Then, use gdrive -h for more information.") return gauth
def drive_logout() -> None: cwd = change_dir() gauth = GoogleAuth() cred_file = gauth.settings.get("save_credentials_file") token = os.path.join(DIR_PATH, cred_file) gauth.LoadCredentials() if not gauth.access_token_expired: print('logging out from the gDrive...') requests.post( url=REVOKE, params={'token': gauth.credentials.access_token}, headers={'Content-type': 'application/x-www-form-urlencoded'}) os.remove(token) os.chdir(cwd)