Skip to main content
Glama
recover-jwt-token.sh7.41 kB
#!/bin/bash # EuConquisto Composer MCP - JWT Token Recovery # Version: 1.0.0 # Purpose: Recover JWT token from backup # Usage: ./scripts/recover-jwt-token.sh [backup_timestamp] set -e # Exit on any error # Configuration PROJECT_ROOT="/Users/ricardokawasaki/Desktop/euconquisto-composer-mcp-poc" BACKUP_ROOT="$PROJECT_ROOT/backups/migration-safety" JWT_PATH="$PROJECT_ROOT/archive/authentication/correct-jwt-new.txt" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Logging functions log() { echo -e "${BLUE}[JWT-RECOVERY]${NC} $1" } success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } error() { echo -e "${RED}[ERROR]${NC} $1" } # Find backup directory find_backup() { local timestamp="$1" if [ -n "$timestamp" ]; then BACKUP_DIR="$BACKUP_ROOT/backup_$timestamp" if [ ! -d "$BACKUP_DIR" ]; then error "Backup not found: $BACKUP_DIR" exit 1 fi else # Find latest backup BACKUP_DIR=$(find "$BACKUP_ROOT" -name "backup_*" -type d | sort | tail -1) if [ -z "$BACKUP_DIR" ]; then error "No backups found in $BACKUP_ROOT" exit 1 fi timestamp=$(basename "$BACKUP_DIR" | sed 's/backup_//') fi log "Using backup: $timestamp" } # Analyze current JWT token state analyze_current_state() { log "Analyzing current JWT token state" if [ -f "$JWT_PATH" ]; then local current_length=$(wc -c < "$JWT_PATH") log "Current JWT token found: $current_length characters" if [ "$current_length" -eq 3276 ]; then success "✅ Current JWT token appears valid (3276 characters)" # Ask user if they want to proceed echo "" warning "Current JWT token appears to be valid." read -p "Do you still want to restore from backup? (y/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then log "Recovery cancelled - current token appears valid" exit 0 fi else error "❌ Current JWT token invalid: $current_length characters (expected 3276)" log "Recovery needed" fi else error "❌ JWT token file not found: $JWT_PATH" log "Recovery needed" fi } # Verify backup JWT token verify_backup_token() { log "Verifying backup JWT token" local backup_jwt="$BACKUP_DIR/tier1-essential/correct-jwt-new.txt" if [ ! -f "$backup_jwt" ]; then error "❌ JWT token not found in backup: $backup_jwt" exit 1 fi local backup_length=$(wc -c < "$backup_jwt") if [ "$backup_length" -ne 3276 ]; then error "❌ Backup JWT token invalid: $backup_length characters (expected 3276)" exit 1 fi success "✅ Backup JWT token verified (3276 characters)" } # Backup current token if it exists backup_current_token() { if [ -f "$JWT_PATH" ]; then log "Backing up current JWT token" local backup_name="jwt-token-backup-$(date +%Y%m%d_%H%M%S).txt" local backup_path="$PROJECT_ROOT/backups/$backup_name" mkdir -p "$(dirname "$backup_path")" cp "$JWT_PATH" "$backup_path" success "✅ Current token backed up to: $backup_path" fi } # Restore JWT token restore_jwt_token() { log "Restoring JWT token from backup" local backup_jwt="$BACKUP_DIR/tier1-essential/correct-jwt-new.txt" # Ensure directory exists mkdir -p "$(dirname "$JWT_PATH")" # Copy token from backup cp "$backup_jwt" "$JWT_PATH" success "✅ JWT token restored" } # Verify restored token verify_restored_token() { log "Verifying restored JWT token" if [ ! -f "$JWT_PATH" ]; then error "❌ Restored JWT token not found" return 1 fi local restored_length=$(wc -c < "$JWT_PATH") if [ "$restored_length" -ne 3276 ]; then error "❌ Restored JWT token invalid: $restored_length characters" return 1 fi success "✅ Restored JWT token verified (3276 characters)" } # Test JWT token functionality test_jwt_functionality() { log "Testing JWT token functionality" # Check if JWT server is running local jwt_server_running=false if lsof -ti :8080 >/dev/null 2>&1; then jwt_server_running=true success "✅ JWT server is running on port 8080" else warning "⚠️ JWT server not running - starting it for test" # Start JWT server temporarily node "$PROJECT_ROOT/tools/servers/jwt-redirect-server-v1.0.2.js" > /dev/null 2>&1 & local jwt_pid=$! sleep 3 if lsof -ti :8080 >/dev/null 2>&1; then success "✅ JWT server started for testing" jwt_server_running=true else error "❌ Failed to start JWT server" return 1 fi fi # Test server response if curl -s "http://localhost:8080" > /dev/null; then success "✅ JWT server responding correctly" else error "❌ JWT server not responding" return 1 fi # Clean up if we started the server if [ "$jwt_server_running" = false ]; then local test_pid=$(lsof -ti :8080 2>/dev/null || true) if [ -n "$test_pid" ]; then kill "$test_pid" 2>/dev/null || true log "Test JWT server stopped" fi fi } # Main execution main() { local timestamp="$1" echo "========================================" echo " EuConquisto Composer JWT Recovery" echo "========================================" echo "" log "Starting JWT token recovery process" echo "" find_backup "$timestamp" analyze_current_state verify_backup_token backup_current_token restore_jwt_token if verify_restored_token && test_jwt_functionality; then echo "" success "🎉 JWT TOKEN RECOVERY COMPLETED" echo "" echo "Recovery Details:" echo " ✅ JWT token restored from backup" echo " ✅ Token length verified (3276 characters)" echo " ✅ JWT server functionality tested" echo "" echo "Next Steps:" echo " 1. Test authentication flow" echo " 2. Verify composition creation works" echo " 3. Monitor for any authentication issues" else error "❌ JWT TOKEN RECOVERY FAILED" error "Authentication may not work correctly" exit 1 fi } # Show usage usage() { echo "Usage: $0 [backup_timestamp]" echo "" echo "Arguments:" echo " backup_timestamp Optional. Specific backup to restore from (format: YYYYMMDD_HHMMSS)" echo "" echo "Examples:" echo " $0 # Use latest backup" echo " $0 20250705_143000 # Use specific backup" echo "" echo "Available backups:" if [ -d "$BACKUP_ROOT" ]; then find "$BACKUP_ROOT" -name "backup_*" -type d | sort | sed 's/.*backup_/ /' else echo " No backups found" fi } # Check arguments if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then usage exit 0 fi # Execute main function main "$@"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rkm097git/euconquisto-composer-mcp-poc'

If you have feedback or need assistance with the MCP directory API, please join our Discord server