Authorization via JWT

#!/usr/bin/env python3
"""
Option 1: Authentication via JWT
  1. Send a login request to POST /user/login and obtain a JWT token.
  2. Include the JWT token in the token request header.
  3. Upload the image to POST /v1/kyc/process.
"""
import requests
import json
import sys

# ===== SETTINGS =====
API_BASE = "https://api.neuro-vision.ru"
LOGIN_URL = f"{API_BASE}/v1/user/login"
PROCESS_URL = f"{API_BASE}/v1/kyc/process"

# Login credentials
LOGIN = "your_email@example.com"   # <-- insert email
PASSWORD = "your_password"          # <-- insert password

SCHEMA_ID = "your-schema-id"       # <-- insert schemaId from Personal Account
IMAGE_PATH = "path/to/your/image.jpg"  # <-- path to image

TIMEOUT = (30, 120)


# --- Step 1: obtaining JWT ---
print("Step 1: Login...")
resp = requests.post(
    LOGIN_URL,
    json={"email": LOGIN, "password": PASSWORD, "valid_days": 5},
    timeout=TIMEOUT,
)
print(f"  Login status: {resp.status_code}")

login_data = resp.json()
print(f"  Response: {json.dumps(login_data, ensure_ascii=False, indent=2)}")

if resp.status_code != 200:
    sys.exit(f"Login error: {resp.status_code}")

jwt = login_data.get("token") or login_data.get("jwt") or login_data.get("accessToken")
if not jwt:
    sys.exit(f"JWT not found in the response. Available keys:{list(login_data.keys())}")

print(f"  JWT received: {jwt[:20]}...")

# --- Step 2: Send the image with JWT in the header ---
print(f"\nStep 2: Sending {IMAGE_PATH}...")
headers = {
    "Token": jwt,
}

data = {
    "schemaId": SCHEMA_ID,
    "mode": "sync",
}

with open(IMAGE_PATH, "rb") as f:
    files = [("images", (IMAGE_PATH.split("/")[-1], f, "image/jpeg"))]
    resp = requests.post(
        PROCESS_URL,
        headers=headers,
        data=data,
        files=files,
        timeout=TIMEOUT,
    )

print(f"Status: {resp.status_code}")
try:
    print(json.dumps(resp.json(), ensure_ascii=False, indent=2))
except Exception:
    print(resp.text)