update
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
14 |
raise HTTPException(status_code=401, detail="Unauthorized access")
|
15 |
-
return
|
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 |
|