Skip to content

Commit 910d91b

Browse files
committed
Read authorization from cookie as well as header
1 parent 7e371cc commit 910d91b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/blueapi/service/authentication.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import httpx
1515
import jwt
1616
import requests
17+
from fastapi import Cookie, Header
1718
from fastapi.requests import HTTPConnection
1819
from fastapi.security import OAuth2AuthorizationCodeBearer
1920
from fastapi.security.utils import get_authorization_scheme_param
@@ -274,8 +275,13 @@ def sync_auth_flow(self, request):
274275
class CommonHttpOAuth(OAuth2AuthorizationCodeBearer):
275276
"""Extended version of OAuth2 Auth to work with both WebSockets and HTTP Requests"""
276277

277-
async def __call__(self, request: HTTPConnection) -> str | None:
278-
authorization = request.headers.get("Authorization")
278+
async def __call__(
279+
self,
280+
request: HTTPConnection,
281+
auth_header: str | None = Header(alias="Authorization", default=None),
282+
auth_cookie: str | None = Cookie(alias="Authorization", default=None),
283+
) -> str | None:
284+
authorization = auth_header or auth_cookie
279285
scheme, param = get_authorization_scheme_param(authorization)
280286
if not authorization or scheme.lower() != "bearer":
281287
if self.auto_error:

0 commit comments

Comments
 (0)