sjyangkevin commented on code in PR #77138:
URL: https://github.com/apache/airflow/pull/77138#discussion_r4644054798


##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -310,23 +314,39 @@ def get_user(self) -> User:
     def session(self):
         return self.appbuilder.session
 
-    @cachedmethod(lambda self: self.cache, key=lambda _, token: 
int(token["sub"]))
     def deserialize_user(self, token: dict[str, Any]) -> User:
         user_id = int(token["sub"])
+        # 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 {user_id} has an invalid 
{TOKEN_GENERATION_CLAIM} claim")
+        user = self._get_active_user(user_id)
+        if token_generation > user.token_generation:
+            # The token was issued after a password change that the cached 
user predates.
+            self.cache.pop(user_id, None)
+            user = self._get_active_user(user_id)
+        if token_generation != user.token_generation:
+            raise ValueError(f"Token of user with id {user_id} was issued 
before their last password change")
+        return user
+
+    @cachedmethod(lambda self: self.cache, key=lambda _, user_id: user_id)
+    def _get_active_user(self, user_id: int) -> User:
+        return self._fetch_active_user(user_id)
 
+    def _fetch_active_user(self, user_id: int) -> User:

Review Comment:
   Removed. Each path has a single load now, `_load_active_user` on the sync 
path and the query in `deserialize_user_async`, and the tests count reads with 
`assert_queries_count`.



-- 
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]

Reply via email to