2024-09-25 21:40:08 +00:00
|
|
|
import os
|
|
|
|
|
from functools import wraps
|
|
|
|
|
from flask import Flask, session, redirect, url_for, request, g, jsonify
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
load_dotenv()
|
|
|
|
|
|
2025-07-08 15:20:10 +01:00
|
|
|
API_KEY = os.getenv("API_KEY")
|
2024-09-25 21:40:08 +00:00
|
|
|
|
|
|
|
|
def auth_check(func):
|
|
|
|
|
@wraps(func)
|
|
|
|
|
def decorated_function(*args, **kwargs):
|
|
|
|
|
auth_header = request.headers.get('Authorization')
|
|
|
|
|
|
|
|
|
|
if not auth_header or not auth_header.startswith('Bearer '):
|
|
|
|
|
return jsonify({"error": "Unauthorized", "message": "API key is missing or invalid."}), 401
|
|
|
|
|
|
|
|
|
|
token = auth_header.split(' ')[1]
|
|
|
|
|
if token != API_KEY:
|
|
|
|
|
return jsonify({"error": "Unauthorized", "message": "API key does not match."}), 401
|
|
|
|
|
|
|
|
|
|
g.authenticated = True
|
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
|
|
|
|
|
|
return decorated_function
|