Skip to content

PyDrive2 2.0: switch to google-auth and require a fresh user login - #395

Merged
shcheklein merged 17 commits into
mainfrom
migrate-google-auth
Nov 21, 2026
Merged

shcheklein merged 17 commits into
mainfrom
migrate-google-auth

Conversation

@shcheklein

@shcheklein shcheklein commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

PyDrive2 2.0 switches to google-auth and google-auth-oauthlib. This removes the
pyOpenSSL dependency and the cryptography upper bound that were needed for
service-account signing with oauth2client. The existing file and dictionary
backends now save google-auth user credentials and persist refreshed tokens.
Clients sharing a cache coordinate refreshes. On Windows, a replacement
credential file receives its access permissions before token data is written.

Upgrading from 1.x

  • OAuth users sign in once with their existing client ID and client secret.
    The fsspec adapter and DVC use a separate default cache for 2.x. For an
    explicitly configured cache, select a fresh file or dictionary key. For CI
    that stores a user token in GDRIVE_CREDENTIALS_DATA, provision the newly
    saved JSON before upgrading the job. The project's live CI uses a separate
    service-account key in GDRIVE_USER_CREDENTIALS_DATA and can keep using it.
  • Service accounts authenticate from their configured JSON or PKCS12 key.
    Deployments that ran solely from a saved 1.x service-account cache need to
    provision the signing key. User credential caches no longer store it.
  • CommandLineAuth() replaces the out-of-band flow reported in deprecation of OAuth out-of-band (OOB) in Google OAuth #173 with a
    loopback callback. It prints a URL to open in a browser. The browser
    must be able to reach that port. For custom web callbacks, retain the
    original flow and its PKCE verifier through the code exchange.
  • Code that accesses GoogleAuth.credentials directly now uses google-auth
    objects. For example, use credentials.token to read the access token.

Validation

  • On Python 3.11 through 3.15, all 38 applicable offline auth tests passed
    locally. They also passed on 3.11 with the minimum Google auth and filelock
    dependencies. Windows CI also covers credential-file permissions and reading
    a WOF-compressed credential file.
  • The full local offline suite passed on Python 3.11 (43 tests). Ruff, mypy,
    and the Sphinx documentation build passed.
  • Four processes sharing an expired credential file made one refresh request
    and reused the rotated token. A built-wheel test exercised a loopback login,
    PKCE exchange, and fsspec file and JSON credentials using simulated Google
    responses. The upgrade test checks that the old cache stays intact.
  • Platform and live Drive tests. The frozen-app packaging test is
    temporarily skipped on Windows with Python 3.15 pending Verify the PyInstaller fix for missing python3t.dll on Windows Python 3.15 #399.

Fixes #89, fixes #361, fixes #369, fixes #374. Supersedes #391, #392,
and #398.

@shcheklein shcheklein changed the title Migrate authentication to google-auth and lift crypto dependency caps PyDrive2 2.0: switch to google-auth and require a fresh user login Nov 20, 2026
@shcheklein shcheklein closed this Nov 20, 2026
@shcheklein shcheklein reopened this Nov 20, 2026

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI generated — Copilot]

Reviewed the google-auth / google-auth-oauthlib migration in #395. Overall the migration is clean and well-structured (symlink protection, atomic writes, AuthorizedHttp refresh persistence, PKCS12 support via cryptography, and v2 fsspec cache separation are all solid). I left a few inline comments on concrete edge cases and a dependency floor mismatch.

Comment thread pydrive2/auth.py Resolved
Comment thread pydrive2/_credentials.py Resolved
Comment thread pydrive2/auth.py Resolved
Comment thread pydrive2/auth.py Resolved
Comment thread pyproject.toml Resolved
Comment thread pydrive2/test/test_auth_flows.py Resolved
# Conflicts:
#	docs/filelist.rst
#	docs/filemanagement.rst
#	docs/fsspec.rst
#	docs/oauth.rst

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The authentication migration needs human end-to-end validation of real Google OAuth callbacks and PKCE beyond mocked tests, and the confirmed Windows Python 3.15 frozen-executable failure requires a release-risk decision.

No open issues 🎉

What changed in this PR

Migrates PyDrive2’s authentication to google-auth for 2.0, removing the deprecated oauth2client stack and requiring a fresh OAuth user login while retaining service-account key authentication.

Changes:

  • Replaces authentication dependencies, removes pyOpenSSL and the cryptography upper bound, and switches command-line login to a loopback callback.
  • Adds user credential storage with refresh-token persistence and a separate default cache for fsspec/DVC.
  • Adds offline authentication regression tests, documents migration requirements, and reformats documentation.
File Description
README.rst Reformats links, badges, and examples.
pyproject.toml Replaces OAuth dependencies and removes signing-related upper bounds.
pydrive2/​test/​test_oauth.py Replaces service-cache tests with an offline storage-reuse check.
pydrive2/​test/​test_auth_flows.py Adds coverage for login, refresh, persistence, signing, and file safety.
pydrive2/​test/​settings/​test_oauth_test_09.yaml Removes the obsolete storage-reuse fixture.
pydrive2/​test/​settings/​test_oauth_test_07.yaml Removes the saved service-account cache fixture.
pydrive2/​test/​settings/​test_oauth_test_06.yaml Removes the deprecated PKCS12 cache fixture.
pydrive2/​test/​README.rst Reformats test setup instructions and corrects numbering.
pydrive2/​settings.py Changes the default redirect URI to localhost.
pydrive2/​fs/​spec.py Separates the default cache and exposes credential migration errors.
pydrive2/​auth.py Migrates OAuth flows, service signing, refresh, and authorized transports.
pydrive2/​_credentials.py Adds user credential serialization, locked refresh persistence, and atomic writes.
docs/​quickstart.rst Reformats setup instructions and code examples.
docs/​pydrive2.rst Corrects an API documentation heading underline.
docs/​oauth.rst Documents loopback login, credential persistence, and migration requirements.
docs/​index.rst Reformats introductory text and project links.
docs/​fsspec.rst Adds cache migration guidance for fsspec and DVC users.
docs/​filemanagement.rst Reformats file-management examples and references.
docs/​filelist.rst Reformats listing examples and references.
CONTRIBUTING.rst Reformats contributor instructions and links.

Review effort: Balanced

Comment thread pydrive2/_credentials.py Fixed

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI generated — Copilot]

Re-reviewed #395 at 8fd2074. All earlier review items look well-addressed — the lock-coordinated shared-cache refresh (_pydrive2_session / _pending_refresh), RSASigner PKCS12 support, Refresh() locking, and Windows DACL preservation are clean and thoroughly tested. I left 3 inline comments on concrete edge cases in Windows reparse-point handling, CredentialStore.load() locking on Windows, and _load_credentials() probing the default client_secrets.json.

Comment thread pydrive2/_windows_credentials.py Resolved
Comment thread pydrive2/_credentials.py Resolved
Comment thread pydrive2/auth.py Resolved
Comment thread pydrive2/_credentials.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Replacing credentials leaves the service’s default transport bound to the previous login, so permission deletion can execute as the wrong user unless the service is invalidated and rebuilt.

1 open issue

Review effort: Balanced

Comment thread pydrive2/auth.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review identifies no active issues requiring changes to the google-auth migration.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants