Registry / gcp / google-auth-oauthlib

google-auth-oauthlib

JSON →
library1.4.1pypypi✓ verified 24d ago

A Python library that provides OAuth 2.0 support for the google-auth library, enabling secure authentication for Google APIs. Current version: 1.3.0, released on February 27, 2026. Maintained with regular updates.

pip install google-auth-oauthlib
INSTALL
IMPORT
SIG · GOOGLE-AUTH-OAUTHL
G
google-auth-oauthlib
gcppythonv1.4.1
Install
4.2s avg
Import
1043ms
Disk
44MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.072s · 44.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.2s · import 1.014s · 45MB
44MB installed
● package 44MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

InstalledAppFlow
from google_auth_oauthlib.flow import InstalledAppFlow
Ensure correct import path to avoid ImportError.

A complete example demonstrating OAuth 2.0 authentication and accessing Google Drive API to list files.

import os from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build # Set up the OAuth 2.0 flow flow = InstalledAppFlow.from_client_secrets_file( 'client_secrets.json', scopes=['https://www.googleapis.com/auth/drive.readonly'] ) # Run the flow to get credentials credentials = flow.run_local_server(port=0) # Build the service service = build('drive', 'v3', credentials=credentials) # Call the Drive API results = service.files().list(pageSize=10, fields='files(id, name)').execute() items = results.get('files', []) if not items: print('No files found.') else: print('Files:') for item in items: print(f'{item['name']} ({item['id']})')
Debug
Known issues
breakingPKCE is enabled by default in version 1.0.0 and later.
fix
Ensure your application supports PKCE or adjust your implementation accordingly.
affects: >=1.0.0
breakingDeprecated OOB code removed in version 1.0.0.
fix
Update your application to use supported redirect URIs.
affects: >=1.0.0
gotchaEnsure 'client_secrets.json' is in the correct directory to avoid FileNotFoundError.
fix
Place 'client_secrets.json' in the same directory as your script or provide the correct path.
affects: all
gotchaRunning the script without internet access will cause the OAuth flow to fail.
fix
Ensure your machine has internet access during the OAuth flow.
affects: all
gotchaUsing an outdated version of google-auth-oauthlib may lead to compatibility issues.
fix
Upgrade to the latest version using 'pip install --upgrade google-auth-oauthlib'.
affects: <1.0.0
breakingIncorrect f-string syntax due to mismatched quotes when accessing dictionary keys within the f-string.
fix
Use different quote types for the f-string and the dictionary keys (e.g., `f"{item['name']}"` or `f'{item["name"]}'`) or escape the inner quotes.
affects: all
breakingThe script failed because the 'googleapiclient' library was not found. This typically means the library is not installed in the environment.
fix
Install the required library using `pip install google-api-python-client`.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'google_auth_oauthlib'
The 'google-auth-oauthlib' library is not installed in your Python environment or the environment where your script is being executed.
fix
Run 'pip install --upgrade google-auth-oauthlib google-auth-httplib2' to install the necessary packages.
Error 400: redirect_uri_mismatch
The redirect URI configured in your application code does not exactly match one of the authorized redirect URIs specified for your OAuth 2.0 client ID in the Google Cloud Console.
fix
Go to the Google Cloud Console, navigate to 'APIs & Services' -> 'Credentials', edit your OAuth 2.0 client ID, and ensure that the 'Authorized redirect URIs' precisely match the URI used in your application's `Flow` configuration, including scheme (http/https), case, and trailing slashes.
AttributeError: 'Credentials' object has no attribute 'to_json'
The `google.oauth2.credentials.Credentials` object from the `google-auth` library does not directly expose a `to_json()` method for serialization as it was present in older, deprecated libraries like `oauth2client`.
fix
Use the `credentials.to_dict()` method to convert the credentials object to a dictionary, then serialize this dictionary to JSON using Python's `json` module, and use `Credentials.from_dict()` to load them back.
oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Token has been expired or revoked.
This error indicates that the refresh token used to obtain a new access token is no longer valid, either because it has expired (e.g., after 7 days in 'Testing' mode), was explicitly revoked by the user, or remained unused for six months.
fix
Prompt the user to re-authenticate to obtain a new set of credentials, and ensure your Google Cloud project's OAuth consent screen publishing status is set to 'Production' if your application is intended for external users beyond test accounts.
InvalidClientSecretsError: File not found: "client_secret.json"
The `client_secrets.json` file, which contains your OAuth 2.0 client credentials, is either missing from the specified or implied path, or the file name is incorrect.
fix
Download the `client_secrets.json` file from the Google Cloud Console and place it in the same directory as your Python script, or provide the correct absolute path to `Flow.from_client_secrets_file()`. Ensure the file is not corrupted and contains the expected 'client_id' and 'client_secret' properties.
Upgrade
Version history
1.4.1latest on PyPI · released Aug 24, 2026
Audit
Dependencies
google-authrequiredProvides core authentication functionality for Google APIs.
Agent activity
34 hits · last 30 days
node
29
OpenAI (training)
1
Resources
google-auth-oauthlib — pip install google-auth-oauthlib · libregistry