or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli-tool.mdhelpers.mdindex.mdinteractive.mdoauth-flows.md
tile.json

tessl/pypi-google-auth-oauthlib

Google Authentication Library - oauthlib integration for OAuth 2.0 flows.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/google-auth-oauthlib@1.2.x

To install, run

npx @tessl/cli install tessl/pypi-google-auth-oauthlib@1.2.0

index.mddocs/

Google Auth OAuthlib

Google 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.

Package Information

  • Package Name: google-auth-oauthlib
  • Language: Python
  • Installation: pip install google-auth-oauthlib
  • CLI Tool: pip install google-auth-oauthlib[tool] (includes CLI functionality)

Core Imports

import google_auth_oauthlib
from google_auth_oauthlib import get_user_credentials

For OAuth flows:

from google_auth_oauthlib.flow import Flow, InstalledAppFlow

For session and credential helpers:

from google_auth_oauthlib.helpers import (
    session_from_client_config,
    credentials_from_session
)

Basic Usage

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()

Architecture

The library provides multiple abstraction levels for OAuth 2.0 flows:

  • High-level functions: Simple credential acquisition (get_user_credentials)
  • Flow classes: Complete OAuth 2.0 flow management (Flow, InstalledAppFlow)
  • Helper utilities: Low-level session and credential conversion
  • CLI tool: Command-line interface for development and testing

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.

Capabilities

Interactive Credential Acquisition

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
): ...

Interactive Authentication

OAuth Flow Management

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, ...): ...

OAuth Flows

Helper Utilities

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): ...

Helper Utilities

Command Line Tool

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-platform

CLI Tool

Error Handling

The library raises standard Python exceptions for common error conditions:

  • ValueError: Invalid client configuration, missing tokens, or malformed parameters
  • ConnectionError: Network connectivity issues or inability to bind to local ports
  • requests_oauthlib exceptions: OAuth-specific errors from underlying library

Types

# 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