API Reference Overview
Complete API reference for the sva-oauth-client package.
Package Structure
sva_oauth_client/
├── client.py # SVAOAuthClient class
├── decorators.py # View decorators
├── middleware.py # Token refresh middleware
├── utils.py # Utility functions
├── views.py # Built-in views
└── urls.py # URL patterns
Core Components
SVAOAuthClient
The main OAuth client class for handling OAuth flows.
Location: sva_oauth_client.client.SVAOAuthClient
Decorators
View decorators for protecting views and requiring specific blocks.
Location: sva_oauth_client.decorators
@sva_oauth_required- Require authentication@sva_blocks_required(*blocks)- Require specific identity blocks
Middleware
Automatic token refresh middleware.
Location: sva_oauth_client.middleware.TokenRefreshMiddleware
Utilities
Helper functions for common operations.
Location: sva_oauth_client.utils
get_sva_claims(request)- Get user claims from data tokenis_authenticated(session)- Check authentication statusget_access_token(session)- Get access tokenget_data_token(session)- Get data tokenclear_oauth_session(session)- Clear OAuth session
Views
Built-in views for OAuth flow.
Location: sva_oauth_client.views
oauth_login- Initiate OAuth flowoauth_callback- Handle OAuth callbackoauth_exchange- Exchange code for tokensoauth_logout- Logout endpoint
Quick Reference
Basic Usage
from sva_oauth_client.decorators import sva_oauth_required
from sva_oauth_client.utils import get_sva_claims
@sva_oauth_required
def my_view(request):
claims = get_sva_claims(request)
return render(request, 'template.html', {'claims': claims})
Requiring Specific Blocks
from sva_oauth_client.decorators import sva_blocks_required
@sva_blocks_required('email', 'name', 'phone')
def profile_view(request):
claims = get_sva_claims(request)
# email, name, phone are guaranteed to exist
return render(request, 'profile.html', {'claims': claims})
Manual Client Usage
from sva_oauth_client.client import SVAOAuthClient
client = SVAOAuthClient(
base_url='https://auth.getsva.com',
client_id='your_client_id',
client_secret='your_client_secret',
redirect_uri='https://yourapp.com/oauth/callback/',
data_token_secret='your_secret',
)
auth_url, code_verifier = client.get_authorization_url()
tokens = client.exchange_code_for_tokens(code, code_verifier)
claims = client.get_blocks_data(tokens['data_token'])
Exceptions
SVAOAuthError
Base exception for all SVA OAuth errors.
from sva_oauth_client.client import SVAOAuthError
try:
# OAuth operation
except SVAOAuthError as e:
# Handle error
SVATokenError
Raised when token operations fail.
from sva_oauth_client.client import SVATokenError
try:
claims = get_sva_claims(request)
except SVATokenError:
# Token expired or invalid
SVAAuthorizationError
Raised when authorization fails.
from sva_oauth_client.client import SVAAuthorizationError
try:
tokens = client.exchange_code_for_tokens(code, code_verifier)
except SVAAuthorizationError:
# Authorization failed
Configuration
All configuration is done via Django settings:
# Required
SVA_OAUTH_BASE_URL = 'https://auth.getsva.com'
SVA_OAUTH_CLIENT_ID = 'your_client_id'
SVA_OAUTH_CLIENT_SECRET = 'your_client_secret'
SVA_OAUTH_REDIRECT_URI = 'https://yourapp.com/oauth/callback/'
SVA_DATA_TOKEN_SECRET = 'your_data_token_secret'
# Optional
SVA_OAUTH_SCOPES = 'openid email profile'
SVA_DATA_TOKEN_ALGORITHM = 'HS256'
SVA_OAUTH_SUCCESS_REDIRECT = '/'
SVA_OAUTH_ERROR_REDIRECT = '/'
SVA_OAUTH_LOGOUT_REDIRECT = '/'
SVA_OAUTH_LOGIN_URL = '/oauth/login/'
Next Steps
- Read Client API for detailed client documentation
- Check Decorators for view protection
- Explore Utilities for helper functions
- See Endpoints for built-in views