{"id":9022,"library":"googleauthentication","title":"Google Authentication","description":"googleauthentication is a Python meta-package designed to simplify connecting to Google services by bundling and abstracting common patterns from official Google authentication libraries like `google-auth`, `google-auth-oauthlib`, and `google-api-python-client`. It provides helper functions to manage OAuth 2.0 flows for web and installed applications. The current version is 0.0.18, and it maintains an active, iterative release schedule typical for pre-1.0 libraries.","status":"active","version":"0.0.18","language":"en","source_language":"en","source_url":"https://github.com/dacker-team/googleauthentication","tags":["google","authentication","oauth","api-client","google-cloud"],"install":[{"cmd":"pip install googleauthentication","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core library for Google API authentication.","package":"google-auth"},{"reason":"Provides OAuth 2.0 support for Installed Applications and Web Server Applications.","package":"google-auth-oauthlib"},{"reason":"Client library for Google's discovery-based APIs.","package":"google-api-python-client"},{"reason":"Adapter for google-auth to use httplib2.","package":"google-auth-httplib2"},{"reason":"Legacy OAuth 2.0 client library; note this library is largely superseded by google-auth for new development.","package":"oauth2client"}],"imports":[{"note":"Functions are located in the `oauth_session` submodule, not directly under the top-level package.","wrong":"from googleauthentication import build_oauth_session","symbol":"build_oauth_session","correct":"from googleauthentication.oauth_session import build_oauth_session"},{"note":"Functions are located in the `oauth_session` submodule, not directly under the top-level package.","wrong":"from googleauthentication import build_oauth_service","symbol":"build_oauth_service","correct":"from googleauthentication.oauth_session import build_oauth_service"},{"note":"Classes are located in the `oauth_session` submodule, not directly under the top-level package.","wrong":"from googleauthentication import OAuthSession","symbol":"OAuthSession","correct":"from googleauthentication.oauth_session import OAuthSession"}],"quickstart":{"code":"import os\nimport json\nfrom googleauthentication.oauth_session import build_oauth_service\n\n# --- Create a dummy client_secrets.json for this example ---\n# In a real scenario, this file is downloaded from Google Cloud Console.\n# DO NOT hardcode secrets in production code.\nclient_secrets_path = \"client_secrets.json\"\ndummy_client_secrets_content = {\n    \"web\": {\n        \"client_id\": os.environ.get(\"GOOGLE_CLIENT_ID\", \"YOUR_CLIENT_ID\"),\n        \"project_id\": \"registry-test-project\",\n        \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n        \"token_uri\": \"https://oauth2.googleapis.com/token\",\n        \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n        \"client_secret\": os.environ.get(\"GOOGLE_CLIENT_SECRET\", \"YOUR_CLIENT_SECRET\"),\n        \"redirect_uris\": [\n            \"http://localhost:8080/\",\n            \"http://localhost\"\n        ]\n    }\n}\nwith open(client_secrets_path, \"w\") as f:\n    json.dump(dummy_client_secrets_content, f)\n# ---------------------------------------------------------\n\nSCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']\nTOKEN_FILE = 'token.json'\n\ntry:\n    # Build an authenticated Google Drive service\n    print(\"Attempting to build Google Drive service...\")\n    drive_service = build_oauth_service(\n        api_name='drive',\n        api_version='v3',\n        client_secrets_json=client_secrets_path,\n        scopes=SCOPES,\n        token_file=TOKEN_FILE\n    )\n    print(\"Service built successfully.\")\n\n    # Example: List up to 5 files\n    print(\"Fetching files...\")\n    results = drive_service.files().list(\n        pageSize=5, fields=\"nextPageToken, files(id, name)\").execute()\n    items = results.get('files', [])\n\n    if not items:\n        print(\"No files found in your Google Drive.\")\n    else:\n        print(\"Files:\")\n        for item in items:\n            print(f\"  {item['name']} ({item['id']})\")\n\nexcept Exception as e:\n    print(f\"An error occurred during authentication or API call: {e}\")\nfinally:\n    # Clean up dummy files created for the example\n    if os.path.exists(client_secrets_path):\n        os.remove(client_secrets_path)\n    if os.path.exists(TOKEN_FILE):\n        os.remove(TOKEN_FILE)\n    print(\"Cleanup complete.\")\n","lang":"python","description":"This quickstart demonstrates how to use `build_oauth_service` to obtain an authenticated Google API client (e.g., Google Drive). It requires a `client_secrets.json` file (downloaded from the Google Cloud Console for your project) and specifies the necessary OAuth scopes. The example will prompt for browser-based authentication if no valid token is found, then list up to 5 files from your Google Drive. Remember to replace placeholder `YOUR_CLIENT_ID` and `YOUR_CLIENT_SECRET` with actual environment variables or ensure your `client_secrets.json` is correctly configured."},"warnings":[{"fix":"Pin your `googleauthentication` dependency to a specific version (e.g., `googleauthentication==0.0.18`) in your `requirements.txt` or `pyproject.toml` to prevent unexpected breaks. Regularly check the GitHub repository for updates before upgrading.","message":"As a pre-1.0 library (version 0.0.x), `googleauthentication` is subject to frequent and potentially undocumented breaking changes between minor versions. API signatures or internal behaviors may change without strict adherence to semantic versioning.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Be aware that while `googleauthentication` provides a convenience layer, deep debugging might require understanding both `google-auth` and `oauth2client` patterns. If you encounter unexpected authentication issues, consider whether conflicts with other Google libraries might be at play.","message":"The library includes `oauth2client` as a dependency, which is largely deprecated and superseded by `google-auth` and `google-auth-oauthlib` for new development. While `googleauthentication` attempts to integrate them, this mix of legacy and modern libraries could lead to confusion or potential conflicts if other parts of your application rely on specific versions or patterns of Google authentication.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Familiarize yourself with the documentation for `google-auth` and `google-api-python-client` to better understand the authentication flows and API interactions abstracted by `googleauthentication`.","message":"The official documentation for `googleauthentication` is minimal, relying heavily on understanding the underlying Google client libraries (e.g., `google-auth`, `google-api-python-client`). This can make troubleshooting or advanced usage challenging without prior knowledge of those libraries.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Download `client_secrets.json` from your Google Cloud Console (APIs & Services -> Credentials -> Create Credentials -> OAuth client ID -> Web application/Desktop app) and place it in the working directory or provide its correct absolute path to `build_oauth_session` or `build_oauth_service`.","cause":"The `client_secrets.json` file, which contains your Google Cloud project's OAuth 2.0 credentials, is missing or the provided path is incorrect.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'client_secrets.json'"},{"fix":"1. Verify `client_secrets.json` credentials are correct and match your Google Cloud project. 2. Ensure all required scopes are specified and that the user has granted consent. 3. Delete the `token.json` file (if used) to force a re-authentication flow, prompting the user for consent again. 4. For internal-only apps, ensure the OAuth consent screen is configured correctly; for external apps, it must be published.","cause":"This usually indicates an issue with the OAuth refresh token, which can be due to incorrect scopes, revoked user permissions, an expired token (especially for sensitive scopes requiring re-authorization), or a mismatch in client ID/secret.","error":"google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})"},{"fix":"Change your import statement from `from googleauthentication import build_oauth_service` to `from googleauthentication.oauth_session import build_oauth_service`.","cause":"The functions `build_oauth_session` and `build_oauth_service` (and the `OAuthSession` class) are not directly available under the top-level `googleauthentication` package but reside within its `oauth_session` submodule.","error":"AttributeError: module 'googleauthentication' has no attribute 'build_oauth_service'"}]}