Google Authentication Library for OAuth 2.0
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.
Warnings
- breaking PKCE is enabled by default in version 1.0.0 and later.
- breaking Deprecated OOB code removed in version 1.0.0.
- gotcha Ensure 'client_secrets.json' is in the correct directory to avoid FileNotFoundError.
- gotcha Running the script without internet access will cause the OAuth flow to fail.
- gotcha Using an outdated version of google-auth-oauthlib may lead to compatibility issues.
Install
-
pip install google-auth-oauthlib
Imports
- InstalledAppFlow
from google_auth_oauthlib.flow import InstalledAppFlow
Quickstart
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']})')