Skip to main content

Authentication model

All auth providers implement the same token-provider shape: synchronous and asynchronous token access for the HTTP clients that SVIClient creates.

Provider flows​

The SDK retries a 401 once, but only when the auth provider exposes invalidate(). It calls invalidate(), re-fetches the token, and replays the request. You don't manage token freshness in application code. StaticTokenProvider has no invalidate(), so the SDK does not retry a 401 against a static token.

Resolution strategy​

When you pass auth= explicitly, SVIClient uses that provider.

When you call SVIClient.from_env(), the SDK resolves auth in this order:

  1. static access token
  2. client credentials
  3. username and password

Why the order matters:

  • the most explicit credential wins
  • automation-friendly flows are preferred over interactive ones
  • the same environment block can support scripts, notebooks, and smoke tests

Provider lifecycles​

  • StaticTokenProvider returns the same token every time
  • ClientCredentialsTokenProvider exchanges client credentials for a token and refreshes in memory
  • UsernamePasswordTokenProvider uses the password grant and refresh token when available
  • AuthorizationCodeTokenProvider runs the PKCE browser flow and then refreshes in memory

Base URL binding​

OAuth-capable providers can inherit base_url, TLS verification, and HTTPX options from the client configuration. That keeps the SAS Logon calls aligned with the service clients.

Practical guidance​

  • use static tokens when another system owns authentication
  • use client credentials for service-to-service workloads
  • use username/password only in controlled development environments
  • use authorization code with PKCE for interactive user sessions