Global Dependency and JWT Permission Validation #11555
Replies: 1 comment
-
FastAPI has a dependency caching mechanism, so
But you have another problem:
This line will be executed before FastAPI app started, and the literal string You can solve it by adding something like this in the
Final working example:
|
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
and PermissionsValidator is defined as:
Description
My use case is that I have a router which has a global dependency to validate jwt tokens. then, i also have endpoints which come under the secure router where i want to check for the permissions.
It seems to me that the jwt token will be validated twice in this scenario - first in the global dependency and then in the endpoint dependency.
Is it possible to do that only once? Somehow if PermissionsValidator could use the validated JWT Token and extract the permissions from that.
Operating System
Mac
Operating System Details
No response
FastAPI Version
No response
Pydantic Version
No response
Python Version
Python 3.12.2
Additional Context
No response
Originally posted by @rohantandon25 in #10388 (reply in thread)
Beta Was this translation helpful? Give feedback.
All reactions