Commit ·
4e13286
1
Parent(s): 1ee60d9
fixing relogin problem
Browse files135 unmodified lines1361371381391401411421431441451461471481491501 unmodified line1521531541551561571584 unmodified lines163164165166167168169170171172173174175176177178135 unmodified linescredentials = Credentials.from_authorized_user_info(creds_data, SCOPES)credentials_from_env = True # Mark as environment credentialsif credentials.refresh_token:try:credentials.refresh(GoogleAuthRequest())except Exception as refresh_error:pass # Use credentials as-is if refresh failsreturn credentialsexcept Exception as e:pass # Fall through to file-based credentials# Check for credentials file (CREDENTIAL_FILE now includes GOOGLE_APPLICATION_CREDENTIALS path if set)if os.path.exists(CREDENTIAL_FILE):1 unmodified linewith open(CREDENTIAL_FILE, "r") as f:creds_data = json.load(f)if "access_token" in creds_data and "token" not in creds_data:creds_data["token"] = creds_data["access_token"]4 unmodified lines# Mark as environment credentials if GOOGLE_APPLICATION_CREDENTIALS was usedcredentials_from_env = bool(os.getenv("GOOGLE_APPLICATION_CREDENTIALS"))if credentials.refresh_token:try:credentials.refresh(GoogleAuthRequest())save_credentials(credentials)except Exception as refresh_error:pass # Use credentials as-is if refresh failsreturn credentialsexcept Exception as e:pass # Fall through to new loginclient_config = {"installed": {135 unmodified lines1361371381391401411421431441451461471481491501511521531541551 unmodified line1571581591601611621634 unmodified lines168169170171172173174175176177178179180181182183184185186187188189190191192135 unmodified linescredentials = Credentials.from_authorized_user_info(creds_data, SCOPES)credentials_from_env = True # Mark as environment credentials# Try to refresh if expired and refresh token existsif credentials.expired and credentials.refresh_token:try:logging.info("Environment credentials expired, attempting refresh...")credentials.refresh(GoogleAuthRequest())logging.info("Environment credentials refreshed successfully")except Exception as refresh_error:logging.warning(f"Failed to refresh environment credentials: {refresh_error}")logging.info("Using existing environment credentials despite refresh failure")return credentialsexcept Exception as e:logging.warning(f"Failed to load environment credentials: {e}")# Fall through to file-based credentials# Check for credentials file (CREDENTIAL_FILE now includes GOOGLE_APPLICATION_CREDENTIALS path if set)if os.path.exists(CREDENTIAL_FILE):1 unmodified linewith open(CREDENTIAL_FILE, "r") as f:creds_data = json.load(f)# Handle different credential formatsif "access_token" in creds_data and "token" not in creds_data:creds_data["token"] = creds_data["access_token"]4 unmodified lines# Mark as environment credentials if GOOGLE_APPLICATION_CREDENTIALS was usedcredentials_from_env = bool(os.getenv("GOOGLE_APPLICATION_CREDENTIALS"))# Try to refresh if expired and refresh token existsif credentials.expired and credentials.refresh_token:try:logging.info("File-based credentials expired, attempting refresh...")credentials.refresh(GoogleAuthRequest())logging.info("File-based credentials refreshed successfully")save_credentials(credentials)except Exception as refresh_error:logging.warning(f"Failed to refresh file-based credentials: {refresh_error}")logging.info("Using existing file-based credentials despite refresh failure")elif not credentials.expired:logging.info("File-based credentials are still valid, no refresh needed")elif not credentials.refresh_token:logging.warning("File-based credentials expired but no refresh token available")return credentialsexcept Exception as e:logging.error(f"Failed to load credentials from file {CREDENTIAL_FILE}: {e}")# Fall through to new login only if credentials are completely unusableclient_config = {"installed": {
src/auth.py+21-7