{"id":9394,"library":"vonage-network-auth","title":"Vonage Network Auth","description":"The `vonage-network-auth` library (version 1.0.2) provides Python tools for interacting with Vonage Network APIs that require OAuth2 for authentication. It focuses on simplifying token acquisition and refresh, allowing developers to securely access network-specific services. Released in November 2023, its release cadence is independent but generally slower than the main Vonage Python SDK.","status":"active","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/Vonage/vonage-python-sdk/tree/main/src/vonage_network_auth","tags":["vonage","oauth","network","authentication","api","oauth2"],"install":[{"cmd":"pip install vonage-network-auth","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for making HTTP requests to the Vonage OAuth2 endpoint.","package":"requests"},{"reason":"Used for working with JSON Web Tokens (JWTs) including decoding and validation.","package":"PyJWT"},{"reason":"A dependency of PyJWT for cryptographic operations.","package":"cryptography"}],"imports":[{"note":"This library is a standalone package, not directly part of the main `vonage` SDK's client object.","wrong":"from vonage import NetworkAuthClient","symbol":"Client","correct":"from vonage_network_auth.client import Client"}],"quickstart":{"code":"import os\nfrom vonage_network_auth.client import Client\n\n# Ensure these are set as environment variables or replace with actual credentials\nclient_id = os.environ.get(\"VONAGE_CLIENT_ID\", \"YOUR_CLIENT_ID\")\nclient_secret = os.environ.get(\"VONAGE_CLIENT_SECRET\", \"YOUR_CLIENT_SECRET\")\nscope = os.environ.get(\"VONAGE_SCOPE\", \"network:quality_of_service\") # Example scope\n\nif not client_id or not client_secret or client_id == \"YOUR_CLIENT_ID\":\n    print(\"Error: VONAGE_CLIENT_ID and VONAGE_CLIENT_SECRET must be set.\")\n    print(\"Please set environment variables or replace placeholders.\")\nelse:\n    try:\n        client = Client(client_id, client_secret)\n        \n        # Request an access token for the specified scope\n        token_response = client.get_access_token(scope)\n        access_token = token_response[\"access_token\"]\n        expires_in = token_response[\"expires_in\"]\n        \n        print(f\"Access Token obtained successfully. Starts with: {access_token[:10]}...\")\n        print(f\"Token expires in: {expires_in} seconds\")\n\n        # If the API provides a refresh token (not all do, depending on scope/grant type)\n        # refresh_token = token_response.get(\"refresh_token\")\n        # if refresh_token:\n        #     print(\"Refresh Token also obtained.\")\n        #     # Example of refreshing the token:\n        #     # refreshed_token_response = client.refresh_access_token(refresh_token, scope)\n        #     # print(f\"Refreshed Access Token: {refreshed_token_response['access_token'][:10]}...\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n        # In a production application, handle specific authentication errors (e.g., InvalidGrant).","lang":"python","description":"This example demonstrates how to initialize the `Client` with your Vonage OAuth2 credentials (Client ID and Client Secret) and retrieve an access token for a specified scope. Remember to replace placeholder values or set them as environment variables (VONAGE_CLIENT_ID, VONAGE_CLIENT_SECRET, VONAGE_SCOPE) for production use."},"warnings":[{"fix":"Import `vonage_network_auth.client.Client` separately and initialize it independently from the main Vonage SDK client.","message":"The `vonage-network-auth` library is a standalone package and not directly integrated into the main `vonage-python-sdk` client object. You cannot access its functionality via `vonage.Client`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Store `expires_in` and `refresh_token` (if provided by the API) and use `client.refresh_access_token()` before making new API calls if the current token is near expiry.","message":"OAuth2 access tokens are typically short-lived. Always implement logic to check token expiry (using the `expires_in` field in the response) and refresh tokens as needed to maintain session validity without requiring user re-authentication.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully review the required scopes for the specific Vonage Network API you intend to use and ensure they are requested accurately in the `get_access_token` call.","message":"Incorrect or missing OAuth2 scopes in the `get_access_token` call will result in `InvalidScope` errors or insufficient permissions for subsequent API calls, even if authentication succeeds.","severity":"breaking","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":"Run `pip install vonage-network-auth` in your terminal to install the library.","cause":"The `vonage-network-auth` package is not installed in your Python environment or is not accessible.","error":"ModuleNotFoundError: No module named 'vonage_network_auth'"},{"fix":"Double-check your Vonage Client ID and Client Secret for typos or invalid values. Verify that the requested `scope` is valid and authorized for your application's credentials.","cause":"This error most commonly indicates that the `client_id`, `client_secret`, or the requested `scope` parameter passed to `get_access_token()` is invalid or incorrect.","error":"requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: .../oauth2/token"},{"fix":"Implement robust token management by checking the `expires_in` value returned with the access token. Prioritize refreshing the token using `client.refresh_access_token()` before making any new API requests if the token is expired or close to expiry.","cause":"While not directly thrown by `vonage-network-auth`, this is a common error encountered when attempting to use an access token (obtained via this library) after its `expires_in` duration has passed.","error":"jwt.exceptions.ExpiredSignatureError: Signature has expired"}]}