Registry / auth-security / vonage-network-auth

vonage-network-auth

JSON →
library1.0.2pypypi✓ verified 84d ago

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.

pip install vonage-network-auth
INSTALL
IMPORT
SIG · VONAGE-NETWORK-AUT
V
vonage-network-auth
auth-securitypythonv1.0.2
Install
4.8s avg
Import
Disk
47MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.2 · 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 0.000s · 48.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 4.8s · import 0.000s · 48MB
47MB installed
● package 47MB
Code
Verified usage

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

NetworkAuth
from vonage_network_auth import NetworkAuth
from vonage_network_auth.client import Client
CreateOidcUrl
from vonage_network_auth import CreateOidcUrl
OidcResponse
from vonage_network_auth import OidcResponse

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.

import os from vonage_network_auth.client import Client # Ensure these are set as environment variables or replace with actual credentials client_id = os.environ.get("VONAGE_CLIENT_ID", "YOUR_CLIENT_ID") client_secret = os.environ.get("VONAGE_CLIENT_SECRET", "YOUR_CLIENT_SECRET") scope = os.environ.get("VONAGE_SCOPE", "network:quality_of_service") # Example scope if not client_id or not client_secret or client_id == "YOUR_CLIENT_ID": print("Error: VONAGE_CLIENT_ID and VONAGE_CLIENT_SECRET must be set.") print("Please set environment variables or replace placeholders.") else: try: client = Client(client_id, client_secret) # Request an access token for the specified scope token_response = client.get_access_token(scope) access_token = token_response["access_token"] expires_in = token_response["expires_in"] print(f"Access Token obtained successfully. Starts with: {access_token[:10]}...") print(f"Token expires in: {expires_in} seconds") # If the API provides a refresh token (not all do, depending on scope/grant type) # refresh_token = token_response.get("refresh_token") # if refresh_token: # print("Refresh Token also obtained.") # # Example of refreshing the token: # # refreshed_token_response = client.refresh_access_token(refresh_token, scope) # # print(f"Refreshed Access Token: {refreshed_token_response['access_token'][:10]}...") except Exception as e: print(f"An error occurred: {e}") # In a production application, handle specific authentication errors (e.g., InvalidGrant).
Debug
Known issues
gotchaThe `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`.
fix
Import `vonage_network_auth.client.Client` separately and initialize it independently from the main Vonage SDK client.
affects: All versions
gotchaOAuth2 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.
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.
affects: All versions
breakingIncorrect 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.
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.
affects: All versions
Upgrade
Version history
1.0.2latest on PyPI · released Nov 29, 2024
Audit
Dependencies
requestsrequiredUsed for making HTTP requests to the Vonage OAuth2 endpoint.
PyJWTrequiredUsed for working with JSON Web Tokens (JWTs) including decoding and validation.
cryptographyrequiredA dependency of PyJWT for cryptographic operations.
Agent activity
37 hits · last 30 days
node
34
Amazon
1
OpenAI (training)
1
Resources
vonage-network-auth — pip install vonage-network-auth · libregistry