Initial Commit
slip slop
This commit is contained in:
commit
064e672ab7
61 changed files with 3504 additions and 0 deletions
17
app/auth.py
Normal file
17
app/auth.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
"""Simple API-key authentication decorator."""
|
||||
import os
|
||||
from functools import wraps
|
||||
from flask import request, jsonify
|
||||
|
||||
|
||||
def require_api_key(f):
|
||||
@wraps(f)
|
||||
def decorated(*args, **kwargs):
|
||||
key = request.headers.get("X-API-Key") or request.args.get("api_key")
|
||||
expected = os.environ.get("API_KEY", "")
|
||||
if not expected:
|
||||
return jsonify({"error": "API key not configured on server"}), 500
|
||||
if key != expected:
|
||||
return jsonify({"error": "Unauthorized"}), 401
|
||||
return f(*args, **kwargs)
|
||||
return decorated
|
||||
Loading…
Add table
Add a link
Reference in a new issue