# Prueft ob Client- und Backend-Token uebereinstimmen. # Im Projektordner ausfuehren: .\deploy\check-token.ps1 $ErrorActionPreference = "Stop" $root = Split-Path $PSScriptRoot -Parent Set-Location $root Write-Host "=== Token-Diagnose ===" -ForegroundColor Cyan Write-Host "" # 1. Token aus backend_token.txt (wie Client) $tokenFile = Join-Path $root "backend_token.txt" $tokenFromFile = "" if (Test-Path $tokenFile) { $tokenFromFile = (Get-Content $tokenFile -Raw -Encoding UTF8).Replace("`ufeff", "").Trim() Write-Host "backend_token.txt: $tokenFromFile" -ForegroundColor Green } else { Write-Host "backend_token.txt: NICHT GEFUNDEN" -ForegroundColor Red } # 2. Token aus .env (wie Backend) $envFile = Join-Path $root ".env" if (Test-Path $envFile) { $envContent = Get-Content $envFile -Raw -Encoding UTF8 if ($envContent -match "MEDWORK_API_TOKEN=(.+)") { $tokenFromEnv = $Matches[1].Trim() Write-Host ".env MEDWORK_API_TOKEN: $tokenFromEnv" -ForegroundColor Green } } # 3. Umgebungsvariablen (falls gesetzt) $envToken = $env:MEDWORK_API_TOKEN $envTokens = $env:MEDWORK_API_TOKENS if ($envToken) { Write-Host "ENV MEDWORK_API_TOKEN: $envToken" -ForegroundColor Yellow } if ($envTokens) { $first = ($envTokens -split ",")[0].Trim() Write-Host "ENV MEDWORK_API_TOKENS (erster): $first" -ForegroundColor Yellow Write-Host " -> ACHTUNG: MEDWORK_API_TOKENS ueberschreibt die Datei!" -ForegroundColor Yellow } # 4. Live-Test gegen Backend Write-Host "" Write-Host "=== Live-Test ===" -ForegroundColor Cyan $testToken = if ($envTokens) { ($envTokens -split ",")[0].Trim() } elseif ($envToken) { $envToken } else { $tokenFromFile } if (-not $testToken) { Write-Host "Kein Token zum Testen gefunden." -ForegroundColor Red exit 1 } $headers = @{ "X-API-Token" = $testToken } try { $r = Invoke-WebRequest -Uri "http://127.0.0.1:8000/health" -Headers $headers -UseBasicParsing -TimeoutSec 5 Write-Host "Health mit Token: OK (HTTP $($r.StatusCode))" -ForegroundColor Green } catch { $code = $_.Exception.Response.StatusCode.value__ if ($code -eq 401) { Write-Host "Health mit Token: 401 Unauthorized - Token wird vom Backend abgelehnt!" -ForegroundColor Red Write-Host "" Write-Host "Loesung: Backend mit gleichem Token starten." -ForegroundColor Yellow Write-Host " - .env muss MEDWORK_API_TOKEN=$testToken enthalten" -ForegroundColor Yellow Write-Host " - Oder: backend_token.txt im Projektordner" -ForegroundColor Yellow } else { Write-Host "Health: Fehler (HTTP $code) - Backend erreichbar?" -ForegroundColor Red } exit 1 } # Transcribe-Endpoint (ohne Datei -> 400 ist OK, 401 waere Token-Fehler) try { $r2 = Invoke-WebRequest -Uri "http://127.0.0.1:8000/v1/transcribe" -Method POST -Headers $headers -ContentType "application/x-www-form-urlencoded" -Body "language=de" -UseBasicParsing -TimeoutSec 5 } catch { $code = $_.Exception.Response.StatusCode.value__ if ($code -eq 401) { Write-Host "Transcribe mit Token: 401 Unauthorized!" -ForegroundColor Red exit 1 } Write-Host "Transcribe: HTTP $code (400 = erwartet ohne Datei, Token OK)" -ForegroundColor Green } Write-Host "" Write-Host "Token-Konfiguration OK." -ForegroundColor Green