Fix the issue of get Authorization header fails during bearer auth (#637)
Co-authored-by: yangben <yangben@zhihu.com>
This commit is contained in:
parent
9d99aee014
commit
a1307abded
1 changed files with 70 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue