Google Authentication Library - oauthlib integration for OAuth 2.0 flows.
83
Command-line tool for obtaining OAuth 2.0 credentials during development and testing. Provides an interactive authentication flow with options for credential storage and scope configuration.
The CLI tool requires additional dependencies:
pip install google-auth-oauthlib[tool]google-oauthlib-tool --client-secrets CLIENT_SECRETS.json --scope SCOPE [OPTIONS]Interactive OAuth 2.0 credential acquisition tool for development workflows.
google-oauthlib-tool
--client-secrets <client_secret_json_file> # Required: Path to OAuth2 client secret JSON
--scope <oauth2_scope> # Required: API scopes (multiple allowed)
[--save] # Optional: Save credentials to file
[--credentials <oauth2_credentials>] # Optional: Path to store credentials# CLI configuration constants
APP_NAME: str = "google-oauthlib-tool"
DEFAULT_CREDENTIALS_FILENAME: str = "credentials.json"
def main(
client_secrets: str, # Path to client secrets JSON file
scope: tuple, # Multiple scopes can be specified
save: bool = False, # Save credentials to file
credentials: str = None # Path to save credentials (default: app dir)
):
"""
Main CLI function for OAuth credential acquisition.
Performs OAuth 2.0 Authorization Code flow to obtain credentials
for testing applications or development workflows.
"""# Obtain credentials for BigQuery access
google-oauthlib-tool \
--client-secrets client_secrets.json \
--scope https://www.googleapis.com/auth/bigquery# Request multiple API scopes
google-oauthlib-tool \
--client-secrets client_secrets.json \
--scope https://www.googleapis.com/auth/cloud-platform \
--scope https://www.googleapis.com/auth/userinfo.email# Save credentials for reuse
google-oauthlib-tool \
--client-secrets client_secrets.json \
--scope https://www.googleapis.com/auth/drive \
--save \
--credentials my_credentials.json# Specify custom save location
google-oauthlib-tool \
--client-secrets client_secrets.json \
--scope https://www.googleapis.com/auth/storage \
--save \
--credentials /path/to/credentials.jsonWhen --save is not specified, credentials are printed to stdout as JSON:
{
"token": "ya29.a0AfH6SMC...",
"refresh_token": "1//-0dGKGb...",
"token_uri": "https://oauth2.googleapis.com/token",
"client_id": "your-client-id.apps.googleusercontent.com",
"client_secret": "your-client-secret",
"scopes": ["https://www.googleapis.com/auth/cloud-platform"]
}When --save is specified, credentials are saved to file without the access token:
{
"refresh_token": "1//-0dGKGb...",
"token_uri": "https://oauth2.googleapis.com/token",
"client_id": "your-client-id.apps.googleusercontent.com",
"client_secret": "your-client-secret",
"scopes": ["https://www.googleapis.com/auth/cloud-platform"]
}No default location - must be specified with --client-secrets
Default save location (when --credentials not specified):
~/.config/google-oauthlib-tool/credentials.json%APPDATA%\google-oauthlib-tool\credentials.json# Load saved credentials in Python code
import json
from google.oauth2.credentials import Credentials
with open('credentials.json', 'r') as f:
creds_data = json.load(f)
credentials = Credentials.from_authorized_user_info(creds_data, creds_data['scopes'])
# Use with Google API clients
from google.cloud import storage
client = storage.Client(credentials=credentials)# Create credentials for CI/CD or testing
google-oauthlib-tool \
--client-secrets ci_client_secrets.json \
--scope https://www.googleapis.com/auth/cloud-platform \
--save \
--credentials test_credentials.json
# Use in tests
export GOOGLE_APPLICATION_CREDENTIALS=test_credentials.json#!/bin/bash
# development_setup.sh
echo "Setting up OAuth credentials for development..."
google-oauthlib-tool \
--client-secrets config/client_secrets.json \
--scope https://www.googleapis.com/auth/cloud-platform \
--scope https://www.googleapis.com/auth/bigquery \
--save
echo "Credentials saved. Ready for development."Common error scenarios:
--save used)--save optionInstall with Tessl CLI
npx tessl i tessl/pypi-google-auth-oauthlibevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10