Skip to main content

nexla_sdk.auth

Authentication utilities for the Nexla SDK

Classes

TokenAuthHandler

Defined in nexla_sdk/auth.py:14

Handles authentication and token management for Nexla API

Supports two authentication flows as per Nexla API documentation:

  1. Service Key Flow: Uses service keys to obtain session tokens via POST to /token endpoint with Authorization: Basic <Service-Key>. Automatically refreshes tokens before expiry using /token/refresh endpoint.

  2. Direct Token Flow: Uses pre-obtained access tokens directly. These tokens expire after a configured interval (usually 1 hour).

Responsible for:

  • Obtaining session tokens using service keys (Basic auth)
  • Using directly provided access tokens (Bearer auth)
  • Refreshing session tokens before expiry (service key flow only)
  • Ensuring valid tokens are available for API requests
  • Handling authentication retries on 401 responses

Methods:

  • ensure_valid_token(self) -> str
    • Source: nexla_sdk/auth.py:145
    • Ensures a valid session token is available, refreshing if necessary
  • execute_authenticated_request(self, method: str, url: str, headers: Dict[str, str], **kwargs) -> Optional[Dict[str, Any]]
    • Source: nexla_sdk/auth.py:170
    • Execute a request with authentication handling
  • get_access_token(self) -> str
    • Source: nexla_sdk/auth.py:69
    • Get the current access token
  • obtain_session_token(self) -> None
    • Source: nexla_sdk/auth.py:83
    • Obtains a session token using the service key
  • refresh_session_token(self) -> None
    • Source: nexla_sdk/auth.py:134
    • Refresh token (compat shim).