Spaces:
Sleeping
Sleeping
Download scripts/debug_admin_auth.py from GodRad/Rag_SaaS_Sys_V4: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/GodRad/Rag_SaaS_Sys_V4/resolve/main/scripts/debug_admin_auth.py
- Command line
-
hf download hf://spaces/GodRad/Rag_SaaS_Sys_V4/scripts/debug_admin_auth.py
-
curl -L -o debug_admin_auth.py https://huggingface.co/spaces/GodRad/Rag_SaaS_Sys_V4/resolve/main/scripts/debug_admin_auth.py
1.84 kB
| 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() | |