import requests import sys BASE_URL = "http://localhost:7860/v1" def debug_admin_auth(): print("Debugging Admin Auth...") # 1. Login login_data = {"username": "admin_test", "password": "password123"} resp = requests.post(f"{BASE_URL}/admin/auth/login", json=login_data) if resp.status_code != 200: # Try registering if login fails print("Login failed, trying registration...") reg_data = { "username": "admin_test", "email": "admin@test.com", "password": "password123", "registration_secret": "change-this-secret-in-production" } requests.post(f"{BASE_URL}/admin/auth/register", json=reg_data) resp = requests.post(f"{BASE_URL}/admin/auth/login", json=login_data) if resp.status_code != 200: print(f"FAILED: Could not login or register admin. Status: {resp.status_code}") print(resp.text) return data = resp.json() token = data["access_token"] print(f"SUCCESS: Got token starting with: {token[:20]}...") # 2. Call /me headers = {"Authorization": f"Bearer {token}"} print(f"Calling /me with headers: {headers}") resp = requests.get(f"{BASE_URL}/admin/auth/me", headers=headers) print(f"RESULT: Status {resp.status_code}") print(f"BODY: {resp.text}") if resp.status_code == 200: print("✓ SUCCESS: /me authenticated correctly") elif resp.status_code == 403: print("✗ FAILURE: Got 403 'Not authenticated' (Header issue?)") elif resp.status_code == 401: print("✗ FAILURE: Got 401 'Invalid token' (JWT decode issue?)") else: print(f"✗ FAILURE: Got unexpected status {resp.status_code}") if __name__ == "__main__": debug_admin_auth()