A Python web application for managing darts games (301 and Cricket) with RabbitMQ integration, real-time updates, and enterprise-grade authentication.
- Multiple Game Modes: 301, 401, 501, and Cricket
- Single & Multi-Player Support: Support for 1-6 players (Cricket max 4)
- RabbitMQ Integration: Receives dart scores through RabbitMQ topic subscription
- Real-time Updates: WebSocket-based real-time game state updates
- Automatic UI Refresh: All connected clients automatically refresh when scores are sent/received
- Web Interface: Clean, responsive web interface for game display and control
- Manual Score Entry: Control panel for manual score entry and game management
- REST API: Full REST API for game control and score submission
- 🆕 OAuth2 Authentication: Secure login with WSO2 Identity Server
- 🆕 Role-Based Access Control: Three-tier role model (Player, Game Master, Admin)
- 🆕 Protected Routes: All endpoints secured with authentication
- 🆕 Permission System: Granular permission-based access control
- 🆕 Session Management: Secure session handling with HttpOnly cookies
- 🆕 Token Validation: JWT signature verification and introspection
- 🆕 API Gateway: Secure REST API layer with OAuth2 authentication
- 🆕 WSO2 Integration: Enterprise-grade identity and API management
- 🆕 Developer Portal: Self-service API access with documentation and analytics
The fastest way to get started with full authentication:
# 1. Run the quick start script
./start-with-auth.sh
# 2. Configure WSO2 (follow the interactive guide)
./configure-wso2-roles.sh
# 3. Update .env with your WSO2 credentials
# 4. Start services again
./start-with-auth.sh
# 5. Access the application
# Open http://localhost:5000 and login!See QUICK_START.md for detailed instructions.
pip install -r requirements.txt# On Ubuntu/Debian
sudo apt-get install rabbitmq-server
# On macOS
brew install rabbitmq
# Start RabbitMQ
sudo systemctl start rabbitmq-server # Linux
brew services start rabbitmq # macOScp .env.example .env
# Edit .env with your settings:
# - RabbitMQ connection
# - Flask configuration
# - WSO2 authentication (for secure mode)# With authentication (recommended)
docker-compose -f docker-compose-wso2.yml up -d
# Without authentication (development only)
docker-compose up -dEdit the .env file to configure:
RABBITMQ_HOST: RabbitMQ server host (default: localhost)RABBITMQ_PORT: RabbitMQ server port (default: 5672)RABBITMQ_USER: RabbitMQ username (default: guest)RABBITMQ_PASSWORD: RabbitMQ password (default: guest)RABBITMQ_EXCHANGE: Exchange name (default: darts_exchange)RABBITMQ_TOPIC: Topic pattern (default: darts.scores.#)
FLASK_HOST: Flask server host (default: 0.0.0.0)FLASK_PORT: Flask server port (default: 5000)FLASK_DEBUG: Debug mode (default: True)SECRET_KEY: Session encryption key (change in production!)
WSO2_IS_URL: WSO2 Identity Server URL (default: https://localhost:9443)WSO2_CLIENT_ID: OAuth2 client ID (get from WSO2 Console)WSO2_CLIENT_SECRET: OAuth2 client secret (get from WSO2 Console)WSO2_REDIRECT_URI: OAuth2 callback URL (default: http://localhost:5000/callback)JWT_VALIDATION_MODE: Token validation method (introspectionorjwks)WSO2_IS_INTROSPECT_USER: Introspection username (default: admin)WSO2_IS_INTROSPECT_PASSWORD: Introspection password (default: admin)SESSION_COOKIE_SECURE: Enable secure cookies (set toTruein production with HTTPS)
See docs/AUTHENTICATION_SETUP.md for detailed configuration guide.
The system implements a three-tier role-based access control model:
Purpose: Basic game participation
Permissions:
- View game board
- Submit dart scores
- View game state
Access: Game board, score submission
Purpose: Game management and coordination
Permissions:
- All Player permissions
- Access control panel
- Create new games
- Add/remove players
- Manage game flow
Access: All Player features + Control panel
Purpose: Full system administration
Permissions:
- All permissions (wildcard
*) - Full system access
- User management (via WSO2)
Access: Complete system access
Test Users (create these in WSO2 Console):
testplayer/Player@123(Player role)testgamemaster/GameMaster@123(Game Master role)testadmin/Admin@123(Admin role)
See AUTHENTICATION_SUMMARY.md for detailed role information.
- Start services:
./start-with-auth.sh-
Access the web interface:
- Login page: http://localhost:5000/login
- Main game board: http://localhost:5000/ (requires login)
- Control panel: http://localhost:5000/control (requires Game Master or Admin role)
- User profile: http://localhost:5000/profile (requires login)
-
Login with test user:
- Use one of the test users created in WSO2
- You'll be redirected to WSO2 login page
- After successful login, you'll be redirected back to the game
- Start the application:
python app.py-
Access the web interface:
- Main game board: http://localhost:5000/
- Control panel: http://localhost:5000/control
- Auto-refresh test page: http://localhost:5000/test-refresh
-
Send scores via RabbitMQ:
The application listens for messages on the configured RabbitMQ exchange and topic.
Message Format (JSON):
{
"score": 20,
"multiplier": "TRIPLE",
"user": "Player 1"
}Multiplier Options:
SINGLE: Single scoreDOUBLE: Double scoreTRIPLE: Triple scoreBULL: Bullseye (25 points)DBLBULL: Double Bullseye (50 points)
- Players start with 301/401/501 points
- Each dart score is subtracted from the player's total
- First player to reach exactly 0 wins
- Going below 0 results in a "bust" - score returns to start of turn
- Players must hit 15, 16, 17, 18, 19, 20, and Bull (25)
- Each number must be hit 3 times to "open" it
- Once opened, additional hits score points
- When all players have hit a number 3 times, it's "closed"
- First player to open all numbers with the highest score wins
-
GET /api/game/state- Get current game state -
POST /api/game/new- Start a new game{ "game_type": "301", "players": ["Player 1", "Player 2"], "double_out": false } -
POST /api/score- Submit a score (triggers automatic UI refresh){ "score": 20, "multiplier": "TRIPLE" } -
GET /api/players- Get all players -
POST /api/players- Add a player{ "name": "Player 3" } -
DELETE /api/players/<player_id>- Remove a player
Note: All API endpoints that modify game state automatically trigger UI refresh for all connected clients via WebSocket.
Client → Server:
new_game- Start a new gameadd_player- Add a playerremove_player- Remove a playernext_player- Move to next playerskip_to_player- Skip to specific playermanual_score- Submit a manual score
Server → Client:
game_state- Game state updateplay_sound- Play a sound effectplay_video- Play a video effectmessage- Display a messagebig_message- Display a big message
Method 1: Interactive Test Page
# Start the application
python app.py
# Open in browser: http://localhost:5000/test-refresh
# Click the test buttons and watch the UI update automatically!Method 2: Automated Test Script
# Start the application in one terminal
python app.py
# Open the game UI in a browser: http://localhost:5000
# Run the test script in another terminal
python examples/test_auto_refresh.py
# Watch the UI update automatically as the script makes API calls!Use the included test script to send test scores:
python test_rabbitmq.pyOr manually publish messages using RabbitMQ tools:
# Install rabbitmq management tools
sudo rabbitmq-plugins enable rabbitmq_management
# Publish a test message
rabbitmqadmin publish exchange=darts_exchange routing_key=darts.scores.test \
payload='{"score": 20, "multiplier": "TRIPLE", "user": "Test Player"}'dartserver-pythonapp/
├── app.py # Main Flask application
├── game_manager.py # Game logic manager
├── rabbitmq_consumer.py # RabbitMQ consumer
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── games/
│ ├── __init__.py
│ ├── game_301.py # 301/401/501 game logic
│ └── game_cricket.py # Cricket game logic
├── templates/
│ ├── index.html # Main game board
│ ├── control.html # Control panel
│ └── test_refresh.html # Auto-refresh test page
├── examples/
│ ├── api_examples.py # API usage examples
│ ├── test_auto_refresh.py # Auto-refresh test script
│ └── websocket_client.py # WebSocket client example
└── static/
├── css/
│ ├── style.css # Main styles
│ └── control.css # Control panel styles
└── js/
├── main.js # Main game board JavaScript
└── control.js # Control panel JavaScript
This Python application can work alongside your existing Node.js darts application. You can:
- Use the Python app as a standalone system with RabbitMQ
- Bridge the Node.js app to send scores to RabbitMQ
- Use the Python app's REST API to integrate with other systems
The application features automatic UI refresh - all connected clients automatically update when:
- Scores are submitted (via API, RabbitMQ, or WebSocket)
- New games are started
- Players are added or removed
- Game state changes
This is implemented using WebSocket (Socket.IO) technology. See docs/AUTO_REFRESH.md for detailed documentation.
Cannot login / "Invalid credentials":
- Verify user exists in WSO2 Console
- Check username and password
- Ensure user has a role assigned
- See QUICK_START.md
"WSO2 Client ID not configured":
- Run
./configure-wso2-roles.sh - Update
.envwith Client ID and Secret - Restart services
"403 Forbidden" on control panel:
- Verify user has Game Master or Admin role
- Check role assignment in WSO2 Console
- See docs/AUTHENTICATION_SETUP.md
"Invalid redirect URI":
- Verify callback URL in WSO2 OAuth2 app:
http://localhost:5000/callback - Check
WSO2_REDIRECT_URIin.env
UI Not Automatically Refreshing?:
- Check browser console for WebSocket connection errors
- Verify Socket.IO client library is loaded
- Visit http://localhost:5000/test-refresh to test the connection
- See docs/AUTO_REFRESH.md for detailed troubleshooting
RabbitMQ Connection Issues:
- Ensure RabbitMQ is running:
sudo systemctl status rabbitmq-server - Check firewall settings
- Verify credentials in
.envfile
WebSocket Connection Issues:
- Check browser console for errors
- Ensure Flask server is running
- Try disabling browser extensions
Game Logic Issues:
- Check server console for error messages
- Verify score message format
- Use the control panel to manually test game logic
Services won't start:
- Check Docker is running
- Verify ports are available (5000, 8080, 9443, 5672, 15672)
- Check Docker resources (4GB+ RAM recommended)
- View logs:
docker-compose -f docker-compose-wso2.yml logs -f
- QUICK_START.md - Get started in 5 steps
- BANNER.txt - System overview and quick reference
- AUTHENTICATION_SETUP.md - Complete authentication guide (500+ lines)
- AUTHENTICATION_FLOW.md - Visual flow diagrams
- AUTHENTICATION_SUMMARY.md - Implementation overview
- docs/README.md - Complete documentation index
./start-with-auth.sh- Quick start with health checks./configure-wso2-roles.sh- Interactive WSO2 configuration./test-authentication.sh- Authentication testing
| Service | URL | Credentials | Purpose |
|---|---|---|---|
| Darts Game | http://localhost:5000 | WSO2 users | Main application |
| WSO2 Console | https://localhost:9443/carbon | admin / admin | Identity management |
| RabbitMQ | http://localhost:15672 | guest / guest | Message broker |
| API Gateway | http://localhost:8080 | Token required | REST API |
# Test authentication
./test-authentication.sh
# Test auto-refresh
python examples/test_auto_refresh.py
# Test RabbitMQ
python test_rabbitmq.py- Login with each role (player, gamemaster, admin)
- Verify access control works correctly
- Test game functionality
- Test logout
See docs/AUTHENTICATION_SETUP.md for detailed test procedures.
dartserver-pythonapp/
├── app.py # Main Flask application
├── auth.py # Authentication module (NEW!)
├── game_manager.py # Game logic manager
├── rabbitmq_consumer.py # RabbitMQ consumer
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── docker-compose-wso2.yml # Docker Compose with WSO2 (NEW!)
├── QUICK_START.md # Quick start guide (NEW!)
├── AUTHENTICATION_SUMMARY.md # Auth implementation summary (NEW!)
├── BANNER.txt # System banner (NEW!)
├── start-with-auth.sh # Quick start script (NEW!)
├── configure-wso2-roles.sh # WSO2 configuration helper (NEW!)
├── test-authentication.sh # Authentication testing (NEW!)
├── docs/
│ ├── README.md # Documentation index (NEW!)
│ ├── AUTHENTICATION_SETUP.md # Complete auth guide (NEW!)
│ ├── AUTHENTICATION_FLOW.md # Flow diagrams (NEW!)
│ └── AUTO_REFRESH.md # Auto-refresh documentation
├── games/
│ ├── __init__.py
│ ├── game_301.py # 301/401/501 game logic
│ └── game_cricket.py # Cricket game logic
├── templates/
│ ├── index.html # Main game board (updated)
│ ├── control.html # Control panel (updated)
│ ├── login.html # Login page (NEW!)
│ └── test_refresh.html # Auto-refresh test page
├── examples/
│ ├── api_examples.py # API usage examples
│ ├── test_auto_refresh.py # Auto-refresh test script
│ └── websocket_client.py # WebSocket client example
└── static/
├── css/
│ ├── style.css # Main styles (updated)
│ └── control.css # Control panel styles (updated)
└── js/
├── main.js # Main game board JavaScript
└── control.js # Control panel JavaScript
- Self-signed SSL certificates (verification disabled)
- HTTP instead of HTTPS for the app
- Default admin credentials for introspection
SESSION_COOKIE_SECURE=False
🔒 For production, you must:
- Enable HTTPS with valid SSL certificates
- Set
SESSION_COOKIE_SECURE=True - Generate strong
SECRET_KEY - Create dedicated service account for introspection
- Enable SSL verification
- Configure firewall rules
- Set up monitoring and logging
See docs/AUTHENTICATION_SETUP.md for complete production guide.
See LICENSE file in the root directory.