feat: update authorization middleware
Browse files
app.py
CHANGED
@@ -300,8 +300,15 @@ import os
|
|
300 |
|
301 |
app = FastAPI()
|
302 |
|
303 |
-
def verify_token(
|
304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
raise HTTPException(status_code=403, detail="Invalid or missing token")
|
306 |
|
307 |
@app.post("/generate")
|
|
|
300 |
|
301 |
app = FastAPI()
|
302 |
|
303 |
+
def verify_token(authorization: str = Header(...)):
|
304 |
+
print("AUTH TOKEN : " , os.getenv("AUTH_TOKEN"))
|
305 |
+
print("authorization : " , authorization)
|
306 |
+
# Extract the token from the Authorization header
|
307 |
+
if not authorization.startswith("Bearer "):
|
308 |
+
raise HTTPException(status_code=403, detail="Invalid or missing token")
|
309 |
+
|
310 |
+
token = authorization.split("Bearer ")[1]
|
311 |
+
if token != os.getenv("AUTH_TOKEN"):
|
312 |
raise HTTPException(status_code=403, detail="Invalid or missing token")
|
313 |
|
314 |
@app.post("/generate")
|