{"id":399,"library":"google-auth-oauthlib","title":"Google Authentication Library for OAuth 2.0","description":"A Python library that provides OAuth 2.0 support for the google-auth library, enabling secure authentication for Google APIs. Current version: 1.3.0, released on February 27, 2026. Maintained with regular updates.","status":"active","version":"1.3.0","language":"python","source_language":"en","source_url":"https://github.com/googleapis/google-auth-library-python-oauthlib","tags":["authentication","OAuth 2.0","Google APIs","Python"],"install":[{"cmd":"pip install google-auth-oauthlib","lang":"bash","label":"Install google-auth-oauthlib"}],"dependencies":[{"reason":"Provides core authentication functionality for Google APIs.","package":"google-auth"}],"imports":[{"note":"Ensure correct import path to avoid ImportError.","symbol":"InstalledAppFlow","correct":"from google_auth_oauthlib.flow import InstalledAppFlow"}],"quickstart":{"code":"import os\nfrom google_auth_oauthlib.flow import InstalledAppFlow\nfrom googleapiclient.discovery import build\n\n# Set up the OAuth 2.0 flow\nflow = InstalledAppFlow.from_client_secrets_file(\n    'client_secrets.json',\n    scopes=['https://www.googleapis.com/auth/drive.readonly']\n)\n\n# Run the flow to get credentials\ncredentials = flow.run_local_server(port=0)\n\n# Build the service\nservice = build('drive', 'v3', credentials=credentials)\n\n# Call the Drive API\nresults = service.files().list(pageSize=10, fields='files(id, name)').execute()\nitems = results.get('files', [])\n\nif not items:\n    print('No files found.')\nelse:\n    print('Files:')\n    for item in items:\n        print(f'{item['name']} ({item['id']})')","lang":"python","description":"A complete example demonstrating OAuth 2.0 authentication and accessing Google Drive API to list files."},"warnings":[{"fix":"Ensure your application supports PKCE or adjust your implementation accordingly.","message":"PKCE is enabled by default in version 1.0.0 and later.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Update your application to use supported redirect URIs.","message":"Deprecated OOB code removed in version 1.0.0.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Place 'client_secrets.json' in the same directory as your script or provide the correct path.","message":"Ensure 'client_secrets.json' is in the correct directory to avoid FileNotFoundError.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure your machine has internet access during the OAuth flow.","message":"Running the script without internet access will cause the OAuth flow to fail.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade to the latest version using 'pip install --upgrade google-auth-oauthlib'.","message":"Using an outdated version of google-auth-oauthlib may lead to compatibility issues.","severity":"gotcha","affected_versions":"<1.0.0"},{"fix":"Use different quote types for the f-string and the dictionary keys (e.g., `f\"{item['name']}\"` or `f'{item[\"name\"]}'`) or escape the inner quotes.","message":"Incorrect f-string syntax due to mismatched quotes when accessing dictionary keys within the f-string.","severity":"breaking","affected_versions":"all"},{"fix":"Install the required library using `pip install google-api-python-client`.","message":"The script failed because the 'googleapiclient' library was not found. This typically means the library is not installed in the environment.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:32:16.353Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Run 'pip install --upgrade google-auth-oauthlib google-auth-httplib2' to install the necessary packages.","cause":"The 'google-auth-oauthlib' library is not installed in your Python environment or the environment where your script is being executed.","error":"ModuleNotFoundError: No module named 'google_auth_oauthlib'"},{"fix":"Go to the Google Cloud Console, navigate to 'APIs & Services' -> 'Credentials', edit your OAuth 2.0 client ID, and ensure that the 'Authorized redirect URIs' precisely match the URI used in your application's `Flow` configuration, including scheme (http/https), case, and trailing slashes.","cause":"The redirect URI configured in your application code does not exactly match one of the authorized redirect URIs specified for your OAuth 2.0 client ID in the Google Cloud Console.","error":"Error 400: redirect_uri_mismatch"},{"fix":"Use the `credentials.to_dict()` method to convert the credentials object to a dictionary, then serialize this dictionary to JSON using Python's `json` module, and use `Credentials.from_dict()` to load them back.","cause":"The `google.oauth2.credentials.Credentials` object from the `google-auth` library does not directly expose a `to_json()` method for serialization as it was present in older, deprecated libraries like `oauth2client`.","error":"AttributeError: 'Credentials' object has no attribute 'to_json'"},{"fix":"Prompt the user to re-authenticate to obtain a new set of credentials, and ensure your Google Cloud project's OAuth consent screen publishing status is set to 'Production' if your application is intended for external users beyond test accounts.","cause":"This error indicates that the refresh token used to obtain a new access token is no longer valid, either because it has expired (e.g., after 7 days in 'Testing' mode), was explicitly revoked by the user, or remained unused for six months.","error":"oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Token has been expired or revoked."},{"fix":"Download the `client_secrets.json` file from the Google Cloud Console and place it in the same directory as your Python script, or provide the correct absolute path to `Flow.from_client_secrets_file()`. Ensure the file is not corrupted and contains the expected 'client_id' and 'client_secret' properties.","cause":"The `client_secrets.json` file, which contains your OAuth 2.0 client credentials, is either missing from the specified or implied path, or the file name is incorrect.","error":"InvalidClientSecretsError: File not found: \"client_secret.json\""}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.14,"mem_mb":16.3,"disk_size":"43.1M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.84,"mem_mb":16.3,"disk_size":"43M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.59,"mem_mb":18.5,"disk_size":"46.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.27,"mem_mb":18.5,"disk_size":"47M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.68,"mem_mb":19.8,"disk_size":"38.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.58,"mem_mb":19.8,"disk_size":"38M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.54,"mem_mb":20.9,"disk_size":"37.6M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.86,"mem_mb":20.9,"disk_size":"38M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":1.04,"mem_mb":16.3,"disk_size":"43.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.95,"mem_mb":16.3,"disk_size":"44M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}