#!/usr/bin/env python3
"""
IRIS OAuth Server Launcher
Avvia il server FastAPI per OAuth Microsoft authentication
"""
import os
import sys
from pathlib import Path
# Add src to path
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))
# Load environment variables
from dotenv import load_dotenv
load_dotenv(project_root / ".env")
def check_config():
"""Check if OAuth is configured"""
client_id = os.getenv("MICROSOFT_CLIENT_ID", "")
client_secret = os.getenv("MICROSOFT_CLIENT_SECRET", "")
redirect_uri = os.getenv("OAUTH_REDIRECT_URI", "")
print("=" * 70)
print("π IRIS OAuth Server")
print("=" * 70)
print()
if not client_id or client_id == "your_client_id_here":
print("β οΈ MICROSOFT_CLIENT_ID not configured!")
print(" β Register app at: https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps/ApplicationsListBlade")
print(" β Add client ID to .env file")
print()
else:
print(f"β
Client ID: {client_id[:10]}...")
if not client_secret or client_secret == "your_client_secret_here":
print("β οΈ MICROSOFT_CLIENT_SECRET not configured!")
print(" β Generate secret in Azure portal")
print(" β Add to .env file")
print()
else:
print("β
Client Secret: configured")
print(f"β
Redirect URI: {redirect_uri}")
print()
if not client_id or not client_secret or \
client_id == "your_client_id_here" or client_secret == "your_client_secret_here":
print("β OAuth NOT configured. Please configure credentials first.")
print()
print("π Setup Instructions:")
print("1. Go to Azure Portal: https://portal.azure.com")
print("2. Navigate to: Azure Active Directory β App registrations")
print("3. Click 'New registration'")
print("4. Set Redirect URI: https://trustypa.brainaihub.tech/oauth/callback")
print("5. Copy Application (client) ID β Add to .env as MICROSOFT_CLIENT_ID")
print("6. Create new client secret β Add to .env as MICROSOFT_CLIENT_SECRET")
print()
return False
return True
def main():
"""Start OAuth server"""
import uvicorn
configured = check_config()
if not configured:
response = input("Start anyway? (y/N): ")
if response.lower() != 'y':
print("Exiting...")
sys.exit(1)
print("=" * 70)
print("π Starting OAuth Server")
print("=" * 70)
print()
print("Server will be available at:")
print(" β’ Local: http://localhost:8000")
print(" β’ Public: https://trustypa.brainaihub.tech")
print()
print("Endpoints:")
print(" β’ Home: /")
print(" β’ Login: /oauth/login")
print(" β’ Callback: /oauth/callback")
print(" β’ Health: /health")
print()
print("Press CTRL+C to stop")
print("=" * 70)
print()
# Start server
uvicorn.run(
"src.oauth_server.app:app",
host="0.0.0.0",
port=8000,
reload=True,
log_level="info",
)
if __name__ == "__main__":
main()