Overview
Fantasy Basketball Analytics uses Yahoo OAuth 2.0 to securely access your fantasy league data. The authentication system handles login, token management, and automatic token refresh to maintain your session.OAuth Flow
The authentication process follows the standard OAuth 2.0 authorization code flow:1. Initial Login
When you click “Login with Yahoo” on the home page, the application initiates the OAuth flow:main.py
The app requests the
fspt-r scope, which grants read-only access to your fantasy sports data. It cannot make changes to your teams or leagues.2. Authorization Callback
After you approve access, Yahoo redirects back to the callback endpoint:main.py
- Exchanges the authorization code for an access token
- Stores the token in your Flask session
- Redirects you to the league selection page
3. Session Storage
Your authentication token is stored in a server-side session with these security settings:main.py
Understanding Session Configuration
Understanding Session Configuration
- SESSION_COOKIE_SAMESITE=“Lax”: Provides CSRF protection while allowing normal navigation
- PERMANENT_SESSION_LIFETIME=60 * 60: Session expires after 1 hour of inactivity
- The session uses Flask’s secret key for encryption
Token Refresh Mechanism
Yahoo access tokens expire after a short period. The app automatically refreshes them when needed:main.py
Automatic Retry Logic
When making API calls, the system automatically detects expired tokens and refreshes them:main.py
Session Management
Protected Routes
Most routes check for authentication before proceeding:main.py
Logging Out
The logout route clears your session data:main.py
What happens when you log out?
What happens when you log out?
- All session data is cleared (tokens, league selection, team name)
- You’re redirected to the home page
- Your browser’s session cookie is invalidated
- You’ll need to re-authenticate with Yahoo to access the app again
Security Considerations
Environment Variables
Yahoo OAuth credentials are stored as environment variables:main.py
Never commit your
YAHOO_CLIENT_ID and YAHOO_CLIENT_SECRET to version control. Use a .env file for local development.Token Security
- Access tokens are never exposed to the client browser
- All API calls are proxied through the Flask backend
- Tokens are encrypted in the session cookie using Flask’s secret key
- Sessions expire after 1 hour of inactivity
HTTPS Enforcement
The OAuth callback uses HTTPS in production:main.py
Troubleshooting
Session expired or 401 errors
Session expired or 401 errors
If you see authentication errors:
- The app will automatically try to refresh your token
- If refresh fails, you’ll be redirected to log in again
- Check that your session hasn’t exceeded the 1-hour timeout
OAuth callback errors
OAuth callback errors
Common issues:
- Invalid redirect URI: Ensure your Yahoo app settings match the callback URL
- Missing environment variables: Verify
YAHOO_CLIENT_IDandYAHOO_CLIENT_SECRETare set - Scope permissions: The app requires the
fspt-rscope for fantasy sports data
Development environment setup
Development environment setup
For local development:The app uses
python-dotenv to load these in development mode.Next Steps
League Selection
Learn how to select and manage your fantasy leagues
Dashboard Navigation
Explore the dashboard interface and features