Skip to content

Commit 1744a09

Browse files
authored
[resotolib][feat] Allow authorization header as cookie (#1305)
1 parent c930dc7 commit 1744a09

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

resotolib/resotolib/asynchronous/web/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def always_allowed(request: Request) -> bool:
3838

3939
@middleware
4040
async def valid_jwt_handler(request: Request, handler: RequestHandler) -> StreamResponse:
41-
auth_header = request.headers.get("authorization")
41+
auth_header = request.headers.get("authorization") or request.cookies.get("resoto_authorization")
4242
if always_allowed(request):
4343
return await handler(request)
4444
elif auth_header:

resotolib/test/asynchronous/web/test_auth.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ async def test_correct_psk(aiohttp_client: Any, app_with_auth: Application) -> N
4040
assert resp.status == 200
4141

4242

43+
@mark.asyncio
44+
async def test_correct_psk_as_cookie(aiohttp_client: Any, app_with_auth: Application) -> None:
45+
client: TestClient = await aiohttp_client(app_with_auth)
46+
jwt = encode_jwt({"foo": "bla"}, "test")
47+
resp = await client.get("/", cookies=CIMultiDict({"resoto_authorization": f"Bearer {jwt}"}))
48+
assert resp.status == 200
49+
50+
4351
@mark.asyncio
4452
async def test_wrong_psk(aiohttp_client: Any, app_with_auth: Application) -> None:
4553
client: TestClient = await aiohttp_client(app_with_auth)

0 commit comments

Comments
 (0)