Registry / gcp / google-oauth

google-oauth

JSON →
library1.0.1pypiunverified

This `google-oauth` library (version 1.0.1, last updated in 2016) is an old, unmaintained Python library for handling OAuth2 for Google APIs, primarily focusing on service accounts. It is considered abandoned and should not be used for new development. Modern applications should instead use the actively maintained `google-auth` and `google-auth-oauthlib` libraries for robust and secure Google authentication.

pip install google-oauth
INSTALL
IMPORT
SIG · GOOGLE-OAUTH
G
google-oauth
gcpenv1.0.1
Install
3.9s avg
Import
1017ms
Disk
38MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.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.910 runs
installs and imports cleanly · install 0.0s · import 1.053s · 39.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.9s · import 0.980s · 40MB
38MB installed
● package 38MB
Code
Verified usage

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

ServiceAccount
from google_oauth import ServiceAccount
Used for authenticating with service accounts.
GoogleService
from google_oauth import GoogleService
Used for making authorized requests.

This quickstart demonstrates how to authenticate a service account using the legacy `google-oauth` library. It initializes `ServiceAccount` with a JSON key and obtains an access token. A placeholder `GoogleService` object is shown for making authorized requests. This code should primarily serve as a reference for *legacy* systems; new implementations should use `google-auth` and `google-auth-oauthlib`.

import os from google_oauth import ServiceAccount, GoogleService # NOTE: This is for a legacy library. For new projects, use google-auth and google-auth-oauthlib. # You would typically load the service account key from a file or environment variable. # For demonstration, we'll use a placeholder. In a real scenario, this would be # a path to your service account JSON key file. SERVICE_ACCOUNT_KEY_PATH = os.environ.get('GOOGLE_SERVICE_ACCOUNT_KEY_PATH', 'path/to/your/service_account_key.json') # The old library's documentation suggests loading from JSON or PKCS12. # Using a dummy dict to simulate loading from json for demonstration. # In reality, you'd load a JSON file like this: # with open(SERVICE_ACCOUNT_KEY_PATH, 'r') as f: # key_data = json.load(f) key_data = { "type": "service_account", "project_id": "your-project-id", "private_key_id": "your-private-key-id", "private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n", "client_email": "your-service-account-email@developer.gserviceaccount.com", "client_id": "your-client-id", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/your-service-account-email%40developer.gserviceaccount.com", "universe_domain": "googleapis.com" } # Define the required API scopes SCOPES = ['https://www.googleapis.com/auth/cloud-platform'] # Example scope try: # Initialize ServiceAccount from JSON (or from_pkcs12) # The original library's `from_json` expects the dictionary content, not a path. # For this example, we'll pass the dummy key_data directly. service_account = ServiceAccount.from_json(key_data, SCOPES) # The access token is available directly access_token = service_account.access_token print(f"Successfully obtained access token (legacy): {access_token[:10]}...") # Use GoogleService to make an authorized request # This part assumes a valid API endpoint exists and would be called. # For a real call, replace 'https://www.googleapis.com/compute/v1/projects' with a valid URL # and ensure the service account has permissions. # This specific example is illustrative, as actual API interaction would require # a more complete setup for an actual Google API client. google_service = GoogleService(service_account) # Example: Attempt to make a dummy request (won't work without a real API call and permissions) # resp = google_service.authorized_request('GET', 'https://www.googleapis.com/compute/v1/projects/your-project-id') # print(f"Response status: {resp.status_code}") except Exception as e: print(f"An error occurred during legacy google-oauth usage: {e}") print("Please note: This library is deprecated. Consider migrating to google-auth and google-auth-oauthlib.")
Debug
Known issues
breakingThe `google-oauth` library is abandoned and has not been updated since 2016 (version 1.0.1). It is not compatible with modern Google API client libraries or recommended best practices for OAuth 2.0. Critical security patches and new features are not being added.
fix
Migrate your application to use `google-auth` for core authentication and `google-auth-oauthlib` for user-facing OAuth flows. These are the officially supported and actively maintained libraries by Google.
affects: All versions (1.0.1 and prior)
gotchaMany online tutorials and code examples for 'Google OAuth Python' refer to the modern `google-auth` and `google-auth-oauthlib` libraries, which have entirely different import paths and usage patterns. Attempting to mix these with the legacy `google-oauth` will lead to `ImportError` or `AttributeError`.
fix
Always verify which library an example is using. For modern Google API interactions, install `google-auth` and `google-auth-oauthlib` (e.g., `pip install google-auth google-auth-oauthlib`).
affects: All versions (1.0.1 and prior)
deprecatedThe `oauth2client` library, a contemporary of `google-oauth` and another deprecated solution, suffered from issues like a fragile design and dependency on the unmaintained `httplib2`. While not identical, `google-oauth` likely shares similar underlying architectural limitations common to older authentication patterns.
fix
The recommended replacement for `oauth2client` and older auth libraries like `google-oauth` is `google-auth`.
affects: All versions (1.0.1 and prior)
Errors
Common errors & fixes
ImportError: cannot import name 'ServiceAccount' from 'google_oauth'
You are trying to import from the legacy `google-oauth` library, but it is either not installed, or your environment is confused with the newer `google-auth` libraries.
fix
Ensure `pip install google-oauth` was run if you *must* use this legacy library. More importantly, reconsider if you intended to use the modern `google-auth` library, which has different import paths (e.g., `from google.oauth2 import service_account`).
SyntaxError: invalid non-printable character U+00A0
This is a generic Python error, often encountered when copying code snippets, especially from web pages or PDFs, which might introduce invisible non-ASCII characters (like a non-breaking space U+00A0) into your Python source file.
fix
Open your Python file in a plain text editor (e.g., VS Code, Sublime Text, Notepad++) configured to display whitespace characters. Manually retype the problematic line, paying attention to any unusual spaces or characters. Ensure your file is saved with UTF-8 encoding.
AttributeError: 'ServiceAccount' object has no attribute 'create_delegated'
You are attempting to use methods or features that might exist in newer `google-auth` libraries, or perhaps in a highly specific fork, but are not present in the old `google-oauth` 1.0.1 library.
fix
Review the very limited documentation and source code for `google-oauth` 1.0.1 to understand its available methods. For advanced features or modern authentication patterns, migrate to `google-auth` and `google-auth-oauthlib`.
Upgrade
Version history
1.0.1latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources

No resource links recorded.

google-oauth — pip install google-oauth · libregistry