sjyangkevin commented on code in PR #77138:
URL: https://github.com/apache/airflow/pull/77138#discussion_r4645894165
##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -326,14 +333,47 @@ def _validate_user(user: User | None, user_id: str) ->
User:
raise ValueError(f"User with id {user_id} is not active")
return user
- @cachedmethod(lambda self: self.cache, key=lambda _, token:
int(token["sub"]))
+ @staticmethod
+ def _get_token_generation(token: dict[str, Any]) -> int:
+ # Tokens issued before the claim existed count as the initial
generation.
+ token_generation = token.get(TOKEN_GENERATION_CLAIM, 0)
+ if type(token_generation) is not int:
+ raise ValueError(
+ f"Token of user with id {token['sub']} has an invalid
{TOKEN_GENERATION_CLAIM} claim"
+ )
+ return token_generation
+
+ def _get_cached_user(self, user_id: int, token_generation: int) -> User |
None:
+ """
+ Return the cached user, unless the token is newer than it.
+
+ A newer token was issued after a password change that the cached user
predates, so the
+ cached user is dropped: it must not match tokens from before the
change either.
+ """
+ with self.cache_lock:
+ user = self.cache.get(user_id)
+ if user is not None and user.token_generation < token_generation:
+ del self.cache[user_id]
Review Comment:
Thanks, sorry for missing this. Updated.
--
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]