Amir8212 commited on
Commit
dabe3cc
·
1 Parent(s): b710e30

feat: update authorization middleware

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -300,8 +300,15 @@ import os
300
 
301
  app = FastAPI()
302
 
303
- def verify_token(x_token: str = Header(...)):
304
- if x_token != os.getenv("AUTH_TOKEN"):
 
 
 
 
 
 
 
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")