Skip to main content

Common Issues

Solutions to common problems when integrating SVA OAuth.

Import Errors

ImportError: No module named 'sva_oauth_client'

Problem: Package not installed.

Solution:

pip install sva-oauth-client

ImportError: cannot import name 'SVAOAuthClient'

Problem: Incorrect import path.

Solution:

# ✅ Correct
from sva_oauth_client.client import SVAOAuthClient

# ❌ Wrong
from sva_oauth_client import SVAOAuthClient

Configuration Issues

redirect_uri_mismatch

Problem: Redirect URI doesn't match registered URI.

Solution:

  • Ensure SVA_OAUTH_REDIRECT_URI exactly matches the redirect URI in your OAuth app
  • Check protocol (http vs https)
  • Check domain
  • Check port (if specified)
  • Check path (including trailing slashes)
# ✅ Correct
SVA_OAUTH_REDIRECT_URI = 'https://yourapp.com/oauth/callback/'

# ❌ Wrong (trailing slash mismatch)
SVA_OAUTH_REDIRECT_URI = 'https://yourapp.com/oauth/callback'

invalid_client

Problem: Invalid client credentials.

Solution:

  • Verify SVA_OAUTH_CLIENT_ID is correct
  • Verify SVA_OAUTH_CLIENT_SECRET is correct
  • Check for typos or extra spaces
  • Ensure credentials are from the correct environment

Invalid data token

Problem: Data token verification fails.

Solution:

  • Ensure SVA_DATA_TOKEN_SECRET matches your SVA provider's secret
  • Check for typos or extra spaces
  • Verify SVA_DATA_TOKEN_ALGORITHM matches (default: 'HS256')

Token Issues

Token expired

Problem: Access token or data token has expired.

Solution:

  • Access tokens expire in 1 hour (default)
  • Data tokens expire in 5 minutes (default)
  • Use TokenRefreshMiddleware for automatic token refresh
  • Handle SVATokenError exceptions gracefully
from sva_oauth_client.utils import get_sva_claims
from sva_oauth_client.client import SVATokenError

try:
claims = get_sva_claims(request)
except SVATokenError:
# Token expired - user will be redirected to login
pass

Token refresh fails

Problem: Refresh token is invalid or expired.

Solution:

  • Refresh tokens expire in 30 days (default)
  • User needs to re-authenticate
  • Clear session and redirect to login
from sva_oauth_client.utils import clear_oauth_session

clear_oauth_session(request.session)
return redirect('sva_oauth_client:login')

Session Issues

Session not persisting

Problem: Session data is lost between requests.

Solution:

  • Ensure django.contrib.sessions is in INSTALLED_APPS
  • Ensure SessionMiddleware is in MIDDLEWARE
  • Check session backend configuration
  • Verify session cookies are being set

Problem: Session cookie security warnings.

Solution:

# settings.py (Production)
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = 'Lax'

Middleware Issues

TokenRefreshMiddleware not working

Problem: Tokens not refreshing automatically.

Solution:

  • Ensure TokenRefreshMiddleware comes after SessionMiddleware
  • Check middleware order in MIDDLEWARE setting
  • Verify session is working correctly
MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware', # Must be first
# ... other middleware
'sva_oauth_client.middleware.TokenRefreshMiddleware', # After SessionMiddleware
]

Decorator Issues

Decorator not redirecting

Problem: @sva_oauth_required not redirecting to login.

Solution:

  • Check SVA_OAUTH_LOGIN_URL setting
  • Verify URL pattern is included: path('oauth/', include('sva_oauth_client.urls'))
  • Check for middleware issues

Blocks not found

Problem: @sva_blocks_required always redirects.

Solution:

  • Ensure requested scopes are approved by user
  • Check that blocks are requested in SVA_OAUTH_SCOPES
  • Verify data token contains the blocks

Connection Issues

Connection refused

Problem: Cannot connect to SVA OAuth provider.

Solution:

  • Verify SVA_OAUTH_BASE_URL is correct
  • Check network connectivity
  • Verify provider is running
  • Check firewall settings

Timeout errors

Problem: Requests timing out.

Solution:

  • Check network latency
  • Verify provider is responsive
  • Increase timeout if needed (not recommended)
  • Check for rate limiting

Development vs Production

Works in development, fails in production

Problem: Different behavior between environments.

Solution:

  • Check environment variables are set correctly
  • Verify HTTPS is configured in production
  • Check session cookie settings
  • Verify redirect URIs match exactly

Debugging Tips

Enable logging

# settings.py
LOGGING = {
'version': 1,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'sva_oauth_client': {
'handlers': ['console'],
'level': 'DEBUG',
},
},
}

Check session data

def debug_view(request):
return JsonResponse({
'has_access_token': 'sva_oauth_access_token' in request.session,
'has_data_token': 'sva_oauth_data_token' in request.session,
'session_keys': list(request.session.keys()),
})

Validate configuration

from django.conf import settings

def validate_config(request):
required = [
'SVA_OAUTH_BASE_URL',
'SVA_OAUTH_CLIENT_ID',
'SVA_OAUTH_CLIENT_SECRET',
'SVA_OAUTH_REDIRECT_URI',
'SVA_DATA_TOKEN_SECRET',
]

missing = [k for k in required if not getattr(settings, k, None)]

return JsonResponse({
'missing': missing,
'all_configured': len(missing) == 0,
})

Getting Help

If you're still experiencing issues:

  1. Check the FAQ
  2. Review Debugging Guide
  3. Check GitHub Issues
  4. Contact support: [email protected]

Next Steps

  • Read the Debugging Guide for detailed debugging steps
  • Check the FAQ for answers to common questions