geqintan commited on
Commit
236b12b
·
1 Parent(s): 4c2fffc
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -10,9 +10,14 @@ logger = logging.getLogger(__name__)
10
 
11
  # 定义依赖项来校验 Authorization
12
  async def check_authorization(authorization: str = Header(..., alias="Authorization")):
13
- if authorization != os.environ.get("AUTHORIZATION"):
 
 
 
 
 
14
  raise HTTPException(status_code=401, detail="Unauthorized access")
15
- return authorization
16
 
17
  app = FastAPI()
18
 
 
10
 
11
  # 定义依赖项来校验 Authorization
12
  async def check_authorization(authorization: str = Header(..., alias="Authorization")):
13
+ # 去掉 Bearer 和后面的空格
14
+ if not authorization.startswith("Bearer "):
15
+ raise HTTPException(status_code=401, detail="Invalid Authorization header format")
16
+
17
+ token = authorization[len("Bearer "):]
18
+ if token != os.environ.get("AUTHORIZATION"):
19
  raise HTTPException(status_code=401, detail="Unauthorized access")
20
+ return token
21
 
22
  app = FastAPI()
23