-
-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async Auth is broken #658
Comments
This comment was marked as outdated.
This comment was marked as outdated.
@shirecoding described behavior is related to Django's standard WSGIRequest/ASGIRequest will set AnonymousUser to I think the root cause of this problem is that the Auth handler does not expect async operations. async def my_auth(request):
request.called = True
return "ok"
@app.get("/my_view", auth=my_auth)
def my_view(request):
auth_called = hasattr(request, "called") and request.called
return {"auth_called": auth_called} $ curl localhost:8000/api/my_view
{"auth_called": false} And you can also see that by making django-ninja/ninja/operation.py Line 150 in 3e46804
I will re-open the PR about this. |
@shirecoding this should work in 0.22 |
I've tried
django_auth
and it does not work with async endpoints because it readsrequest.user.is_authenticated
which access the database, ok so i followed the "custom" authentication method as described in the documentationI tried accessing the API
cron_pretty
without passing in any cookies, and it still manages to allow it to pass through! pretty dangerous. the only way is to throw an exception inside the auth function, but the documentation makes it sounds like django ninja handles this which is misleadingThe text was updated successfully, but these errors were encountered: