24 lines
710 B
Python
24 lines
710 B
Python
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)
|