mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
Fix the issue of get Authorization header fails during bearer auth (#637)
Co-authored-by: yangben <yangben@zhihu.com>
This commit is contained in:
@@ -34,8 +34,15 @@ class BearerAuthBackend(AuthenticationBackend):
|
||||
self.provider = provider
|
||||
|
||||
async def authenticate(self, conn: HTTPConnection):
|
||||
auth_header = conn.headers.get("Authorization")
|
||||
if not auth_header or not auth_header.startswith("Bearer "):
|
||||
auth_header = next(
|
||||
(
|
||||
conn.headers.get(key)
|
||||
for key in conn.headers
|
||||
if key.lower() == "authorization"
|
||||
),
|
||||
None,
|
||||
)
|
||||
if not auth_header or not auth_header.lower().startswith("bearer "):
|
||||
return None
|
||||
|
||||
token = auth_header[7:] # Remove "Bearer " prefix
|
||||
|
||||
Reference in New Issue
Block a user