| 69 | |
| 70 | @wraps(f) |
| 71 | def decorated(*args, **kwargs): |
| 72 | auth_header = request.headers.get("Authorization", "") |
| 73 | if not auth_header.startswith("Bearer "): |
| 74 | return jsonify( |
| 75 | { |
| 76 | "success": False, |
| 77 | "errors": [{"code": 10000, "message": "Authentication error"}], |
| 78 | "messages": [], |
| 79 | "result": None, |
| 80 | } |
| 81 | ), 401 |
| 82 | |
| 83 | token = auth_header[7:] # Remove "Bearer " prefix |
| 84 | |
| 85 | # If VALID_TOKENS is set, validate against it; otherwise accept any token |
| 86 | if VALID_TOKENS and token not in VALID_TOKENS: |
| 87 | return jsonify( |
| 88 | { |
| 89 | "success": False, |
| 90 | "errors": [{"code": 10000, "message": "Invalid API token"}], |
| 91 | "messages": [], |
| 92 | "result": None, |
| 93 | } |
| 94 | ), 403 |
| 95 | |
| 96 | return f(*args, **kwargs) |
| 97 | |
| 98 | return decorated |
| 99 | |