vincbeck commented on issue #60265:
URL: https://github.com/apache/airflow/issues/60265#issuecomment-3739246381
You are absolutely right! Sorry about that. I think, indeed, we could do
some optimizations here, as you mention we might be calling
`get_auth_manager().get_user_from_token` too many times. However, I would still
like keeping the method `refresh_user` for refreshing users/tokens only. What
we could do then is something like that in
`airflow-core/src/airflow/api_fastapi/auth/middlewares/refresh_token.py`
```
if current_token:
new_user, current_user = await
self._refresh_user(current_token)
if user := (new_user or current_user):
request.state.user = user
response = await call_next(request)
if new_user:
```
And update `_refresh_user`:
```
@staticmethod
async def _refresh_user(current_token: str) -> BaseUser | None:
try:
user = await resolve_user_from_token(current_token)
except HTTPException:
return None, user
return get_auth_manager().refresh_user(user=user), user
```
What do you think?
--
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]