RehanAhmad25 commented on code in PR #76741:
URL: https://github.com/apache/airflow/pull/76741#discussion_r4665114083
##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -171,6 +171,19 @@ async def get_user(
return await
resolve_user_from_token(request.cookies.get(COOKIE_NAME_JWT_TOKEN))
+async def get_optional_user(
+ request: Request,
+ bearer_credentials: HTTPAuthorizationCredentials | None =
Depends(bearer_scheme),
+) -> BaseUser | None:
+ """Return the authenticated user, or ``None`` when the request is
unauthenticated."""
+ try:
+ return await get_user(request, _oauth_token=None,
bearer_credentials=bearer_credentials)
+ except HTTPException as error:
Review Comment:
nit: could you add a short comment on why this catches both `401` and `403`?
`resolve_user_from_token` returns `401` for missing/expired tokens but `403`
for an invalid JWT, so both mean "unauthenticated" here. Making that explicit
stops someone from removing `403` later and breaking the invalid-cookie
redirect.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]