This commit is contained in:
JMARyA 2024-12-08 14:21:32 +01:00
commit b2f6f60d5e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 45 additions and 0 deletions

11
Dockerfile Normal file
View file

@ -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"]

10
docker-compose.yml Normal file
View file

@ -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

24
main.py Normal file
View file

@ -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)