Update app.py
Browse files24 unmodified lines2526272829309 unmodified lines40414243444546474849505152535464 unmodified lines11912012112212312412512612724 unmodified linesdef validate_app_check_token(app_check_token: str) -> bool:try:service_account_info = json.loads(os.environ["FIREBASE_SERVICE_ACCOUNT_JSON"])credentials = service_account.Credentials.from_service_account_info(service_account_info,9 unmodified linesif not app_id:continueurl = f"https://firebaseappcheck.googleapis.com/v1/projects/{project_id}/apps/{app_id}:verifyAppCheckToken"response = authed_session.post(url, json={"appCheckToken": app_check_token})if response.status_code == 200:return Truereturn Falseexcept Exception as e:print(f"App Check validation error: {e}")return Falsedef download_video_audio_and_metadata(url: str) -> tuple[str, str, str]:64 unmodified linesx_firebase_appcheck: str = Header(None)):if not x_firebase_appcheck:return JSONResponse(status_code=403, content={"error": "Missing Firebase App Check token"})if not validate_app_check_token(x_firebase_appcheck):return JSONResponse(status_code=403, content={"error": "Invalid App Check token"})audio_url = request.audio_urlgemini_api_key = request.gemini_api_key24 unmodified lines252627282930319 unmodified lines41424344454647484950515253545556575859606164 unmodified lines12612712812913013113213313413513613713813914024 unmodified linesdef validate_app_check_token(app_check_token: str) -> bool:try:print("[AppCheck] Validating App Check token...")service_account_info = json.loads(os.environ["FIREBASE_SERVICE_ACCOUNT_JSON"])credentials = service_account.Credentials.from_service_account_info(service_account_info,9 unmodified linesif not app_id:continueprint(f"[AppCheck] Trying App ID: {app_id}")url = f"https://firebaseappcheck.googleapis.com/v1/projects/{project_id}/apps/{app_id}:verifyAppCheckToken"response = authed_session.post(url, json={"appCheckToken": app_check_token})print(f"[AppCheck] Status code for {app_id}: {response.status_code}")print(f"[AppCheck] Response body: {response.text}")if response.status_code == 200:print(f"[AppCheck] ✅ Token valid for App ID: {app_id}")return Trueprint("[AppCheck] ❌ Token invalid for all App IDs")return Falseexcept Exception as e:print(f"[AppCheck] 🔥 Exception while validating App Check token: {e}")return Falsedef download_video_audio_and_metadata(url: str) -> tuple[str, str, str]:64 unmodified linesx_firebase_appcheck: str = Header(None)):if not x_firebase_appcheck:print("[/analyze] ❌ Missing App Check token")return JSONResponse(status_code=403, content={"error": "Missing Firebase App Check token"})print("[/analyze] App Check token received")if not validate_app_check_token(x_firebase_appcheck):print("[/analyze] ❌ Invalid App Check token")return JSONResponse(status_code=403, content={"error": "Invalid App Check token"})print("[/analyze] ✅ App Check token validated")audio_url = request.audio_urlgemini_api_key = request.gemini_api_key
app.py+16-3