commit b2f6f60d5e4a9eae69b0ec6bde5914e00c221cb7 Author: JMARyA Date: Sun Dec 8 14:21:32 2024 +0100 init diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6d74a26 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.9-slim + +WORKDIR /app + +RUN pip install Flask + +COPY main.py /app/main.py + +EXPOSE 5000 + +CMD ["python", "main.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3575a7a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.8' + +services: + forward-auth: + build: git.hydrar.de/hydra/forward_api_key_auth + ports: + - "11405:5000" + volumes: + - ./auth.txt:/app/auth.txt + restart: unless-stopped diff --git a/main.py b/main.py new file mode 100644 index 0000000..fd7b270 --- /dev/null +++ b/main.py @@ -0,0 +1,24 @@ +from flask import Flask, request, jsonify + +app = Flask(__name__) + +valid_tokens = open("auth.txt").read().split("\n") + +@app.route("/auth", methods=["GET", "POST"]) +def authenticate(): + # Get the bearer token from the Authorization header + token = request.headers.get("Authorization") + if not token or not token.startswith("Bearer "): + return jsonify({"error": "Invalid token"}), 401 + + # Extract the token value + token = token.split(" ")[1] + + # Check if the token is valid + if token in valid_tokens: + return jsonify({"status": "success"}), 200 + else: + return jsonify({"error": "Invalid token"}), 401 + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000)