Google Authentication Library - oauthlib integration for OAuth 2.0 flows.
npx @tessl/cli install tessl/pypi-google-auth-oauthlib@1.2.0Google Authentication Library - oauthlib integration provides seamless OAuth 2.0 flows for Google services authentication. It offers high-level abstractions for common authentication patterns including web application flows, installed application flows, and interactive credential acquisition, with built-in support for token refresh, credential storage, and various Google OAuth 2.0 endpoints.
pip install google-auth-oauthlibpip install google-auth-oauthlib[tool] (includes CLI functionality)import google_auth_oauthlib
from google_auth_oauthlib import get_user_credentialsFor OAuth flows:
from google_auth_oauthlib.flow import Flow, InstalledAppFlowFor session and credential helpers:
from google_auth_oauthlib.helpers import (
session_from_client_config,
credentials_from_session
)import google_auth_oauthlib
# Simple interactive credential acquisition
scopes = ['https://www.googleapis.com/auth/cloud-platform']
client_id = 'your-client-id.apps.googleusercontent.com'
client_secret = 'your-client-secret'
credentials = google_auth_oauthlib.get_user_credentials(
scopes, client_id, client_secret
)
# Use credentials with Google API clients
from google.cloud import bigquery
bigquery_client = bigquery.Client(credentials=credentials)For installed applications:
from google_auth_oauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.from_client_secrets_file(
'client_secrets.json',
scopes=['https://www.googleapis.com/auth/cloud-platform']
)
credentials = flow.run_local_server()The library provides multiple abstraction levels for OAuth 2.0 flows:
get_user_credentials)Flow, InstalledAppFlow)This design enables both quick integration for simple use cases and fine-grained control for complex authentication scenarios across web applications, desktop applications, CLI tools, and interactive environments.
High-level functions for obtaining user credentials in interactive development environments like Jupyter notebooks. Provides automatic port detection and simplified OAuth flow management.
def get_user_credentials(
scopes, client_id, client_secret,
minimum_port=8080, maximum_port=None
): ...Complete OAuth 2.0 authorization flow implementation with support for both web and installed application patterns. Handles authorization URL generation, token exchange, and credential management.
class Flow:
def __init__(self, oauth2session, client_type, client_config, ...): ...
@classmethod
def from_client_config(cls, client_config, scopes, **kwargs): ...
def authorization_url(self, **kwargs): ...
def fetch_token(self, **kwargs): ...
class InstalledAppFlow(Flow):
def run_local_server(self, host="localhost", port=8080, ...): ...Low-level utilities for session management and credential conversion between requests-oauthlib sessions and google-auth credentials objects.
def session_from_client_config(client_config, scopes, **kwargs): ...
def credentials_from_session(session, client_config=None): ...CLI tool for obtaining OAuth credentials during development and testing. Provides interactive authentication flow with credential storage options.
google-oauthlib-tool --client-secrets client.json --scope https://www.googleapis.com/auth/cloud-platformThe library raises standard Python exceptions for common error conditions:
# Common type hints used throughout the API
from typing import Sequence, Mapping, Any, Optional, Tuple
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import AuthorizedSession
import requests_oauthlib