Universal Verification Broker (UVB) Python SDK
Project description
uvb-client
Python SDK for Universal Verification Broker (UVB).
Installation
pip install uvb-client
Quick Start
import asyncio
from uvb import UVBClient
async def main():
# Initialize the client
async with UVBClient(
tenant_id="my-tenant",
uvb_url="http://localhost:8080",
api_key="optional-api-key"
) as client:
# Verify a user with TOTP
response = await client.verify(
user_id="user123",
factor_type="totp",
factor_value="123456"
)
if response.success:
print(f"Verification successful! Session: {response.session_id}")
else:
print(f"Verification failed: {response.error}")
# Validate a session
session = await client.validate_session(
session_token=response.session_token
)
print(f"User: {session.user_id}")
print(f"Factors verified: {session.factors_verified}")
asyncio.run(main())
API Reference
UVBClient
__init__(tenant_id, uvb_url, api_key, timeout)
Initialize the UVB client.
Parameters:
tenant_id(required): Your UVB tenant identifieruvb_url(optional): Base URL of the UVB server (default:http://localhost:8080)api_key(optional): API key for server-to-server authenticationtimeout(optional): Request timeout in seconds (default: 30.0)
verify(user_id, factor_type, factor_value, metadata)
Verify a user with a specific authentication factor.
Parameters:
user_id(required): User identifierfactor_type(required): Authentication factor type (totp,webauthn,email_otp, etc.)factor_value(optional): Factor value (e.g., TOTP code)metadata(optional): Additional metadata dictionary
Returns: VerificationResponse
response = await client.verify(
user_id="user123",
factor_type="totp",
factor_value="123456"
)
validate_session(session_token)
Validate a session token and retrieve session information.
Parameters:
session_token(required): Session token to validate
Returns: UVBSession
session = await client.validate_session(
session_token="eyJ0eXAiOiJKV1QiLCJhbGc..."
)
revoke_session(session_id)
Revoke a session.
Parameters:
session_id(required): Session identifier to revoke
Returns: bool (True if successful)
await client.revoke_session(session_id="sess_123")
enroll_factor(user_id, factor_type, metadata)
Enroll a new authentication factor for a user.
Parameters:
user_id(required): User identifierfactor_type(required): Factor type to enrollmetadata(optional): Additional metadata dictionary
Returns: EnrollmentResponse
enrollment = await client.enroll_factor(
user_id="user123",
factor_type="totp"
)
print(f"QR Code: {enrollment.qr_code}")
print(f"Secret: {enrollment.secret}")
list_user_factors(user_id)
List all enrolled factors for a user.
Parameters:
user_id(required): User identifier
Returns: list[dict]
factors = await client.list_user_factors(user_id="user123")
for factor in factors:
print(f"Factor: {factor['type']}, ID: {factor['id']}")
remove_factor(user_id, factor_id)
Remove an enrolled factor from a user.
Parameters:
user_id(required): User identifierfactor_id(required): Factor identifier to remove
Returns: bool (True if successful)
await client.remove_factor(
user_id="user123",
factor_id="factor_456"
)
Types
UVBSession
Session information returned by validate_session().
@dataclass
class UVBSession:
user_id: str
tenant_id: str
session_id: str
factors_verified: list[str]
expires_at: datetime
status: SessionStatus
metadata: dict[str, Any]
VerificationResponse
Response from verify() operation.
@dataclass
class VerificationResponse:
success: bool
session_id: str | None
session_token: str | None
expires_at: datetime | None
factors_verified: list[str]
message: str | None
error: str | None
EnrollmentResponse
Response from enroll_factor() operation.
@dataclass
class EnrollmentResponse:
success: bool
enrollment_id: str | None
qr_code: str | None # For TOTP
secret: str | None # For TOTP
challenge: dict | None # For WebAuthn
message: str | None
error: str | None
FactorType
Enum of supported authentication factor types:
OAUTHTOTPWEBAUTHNEMAIL_OTPSMS_OTPWHATSAPPVOICE_CALLPUSH
Examples
Multi-Factor Authentication
async def verify_with_mfa(client, user_id):
# First factor: TOTP
response1 = await client.verify(
user_id=user_id,
factor_type="totp",
factor_value="123456"
)
if not response1.success:
return False
# Second factor: WebAuthn
response2 = await client.verify(
user_id=user_id,
factor_type="webauthn",
factor_value=webauthn_credential
)
return response2.success
Context Manager Usage
async with UVBClient(tenant_id="my-tenant") as client:
response = await client.verify(
user_id="user123",
factor_type="totp",
factor_value="123456"
)
# Client automatically closes when exiting context
Error Handling
from uvb import UVBClient, UVBAuthenticationError, UVBAPIError
async def safe_verify(client, user_id, code):
try:
response = await client.verify(
user_id=user_id,
factor_type="totp",
factor_value=code
)
return response.success
except UVBAuthenticationError as e:
print(f"Authentication failed: {e}")
return False
except UVBAPIError as e:
print(f"API error (status {e.status_code}): {e}")
return False
Enrolling Multiple Factors
async def setup_user_mfa(client, user_id):
# Enroll TOTP
totp_enrollment = await client.enroll_factor(
user_id=user_id,
factor_type="totp"
)
print(f"TOTP Secret: {totp_enrollment.secret}")
print(f"QR Code: {totp_enrollment.qr_code}")
# Enroll WebAuthn
webauthn_enrollment = await client.enroll_factor(
user_id=user_id,
factor_type="webauthn"
)
print(f"WebAuthn Challenge: {webauthn_enrollment.challenge}")
# List all factors
factors = await client.list_user_factors(user_id=user_id)
print(f"User has {len(factors)} factors enrolled")
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Type checking
mypy uvb
# Code formatting
black uvb
ruff check uvb
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uvb_client-0.2.1.tar.gz.
File metadata
- Download URL: uvb_client-0.2.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
476e0a4dcf9356c0022ce40003f66914de183f4d69b4cc5c73d17e35589cf92f
|
|
| MD5 |
4e7644afc5128de0b0704d6985a3f019
|
|
| BLAKE2b-256 |
e7b15cbffa4a6850df98fd6d245f35a7b27321c0979e8d1205c67ec10f24c231
|
File details
Details for the file uvb_client-0.2.1-py3-none-any.whl.
File metadata
- Download URL: uvb_client-0.2.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31121b20e9aac4520af4ee0ea56d87b9868212ca16e97453b0661f232214fe10
|
|
| MD5 |
e565c8e3abd369c531cc61a618abead4
|
|
| BLAKE2b-256 |
524532984e3ea4373cd842eeff0549910639a5c828dca4692f31071c1bf3bdcc
|