{"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,"search_vec":"'1.3.0':29 '2.0':6,13,41 '2026':34 '27':33 'api':26,43 'auth':19 'authent':2,23,39 'current':27 'enabl':21 'februari':32 'googl':1,18,25,42 'google-auth':17 'librari':3,9,20 'maintain':35 'oauth':5,12,40 'provid':11 'python':8,44 'regular':37 'releas':30 'secur':22 'support':14 'updat':38 'version':28","created_at":"2026-03-28T11:14:57.657145+00:00","updated_at":"2026-04-16T15:18:54.249464+00:00","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,"quickstart_score":0,"quickstart_tag":"stale","pypi_latest":"1.4.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/googleapis/google-cloud-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/google-auth-oauthlib/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["gcp","auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}