Replies: 2 comments 4 replies
-
|
I can reproduce this with from litestar import post
from litestar.connection import ASGIConnection
from litestar.di import Provide
from litestar.security.jwt import JWTAuth, Token
from litestar.testing import create_test_client
async def retrieve_user_handler(token: Token, connection: ASGIConnection) -> None:
pass
jwt_auth = JWTAuth(retrieve_user_handler=retrieve_user_handler, token_secret="")
@post("/", exclude_from_auth=True)
async def login(jwt: JWTAuth) -> None:
return None
with create_test_client(
[login],
dependencies={
"jwt": Provide(lambda: jwt_auth, sync_to_thread=False, use_cache=True),
},
raise_server_exceptions=True,
) as client:
print(client.post("/"))@aranvir just a tip: When providing bug reports, it's always best to keep the example as minimal as possible :) What's interesting about this is that even if you do |
Beta Was this translation helpful? Give feedback.
-
|
facing the same on trying to use the jwt_auth instance in a handler in the context of a app factory (see https://discord.com/channels/919193495116337154/1331963919605956608 but the discussion here is better described than my ramblings) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I want to make a reference to my
JWTAuthobject available via dependency injection. My motivation is that I want to create it only once and thus not use an import statement to fetch it from the module. After some digging in this I realized that it's probably not an issue, sinceJWTAuthdoes not manage any state so as long as the inputs don't change it would have been okay to instantiate it multiple times.However, I was very confused why I could not (easily) provide a reference via dependency injection. I attached a full example at the end of the post. In short:
JWTAuth, I get anNameError: name 'ASGIConnection' is not definedexception. The stack trace does not make any sense to me.Any, it works fine.Dependency(skip_validation=True)it also works.So, I guess it has something to do with the inner workings of litestar but I did not expect that behavior at all and it took me too long to figure out the source of the issue :D so I was wondering: is it intended or an oversight?
Beta Was this translation helpful? Give feedback.
All reactions