Skip to content

What middleware for Django's session authentication for graphene-django? #1159

Answered by thomergil
thomergil asked this question in Q&A
Discussion options

You must be logged in to vote

I took a stab at this myself, partly inspired and stolen from other similar libraries.

A proof of concept implementation would look as follows. I'm pretty sure there are still problems all over the place, but it seems to correctly set request.user based on the configured AUTHENTICATION_BACKENDS, which in the case of django.contrib.auth.backends.ModelBackend means using sessionid in the Cookie header.

First add MIDDLEWARE to GRAPHENE, to point at the class that implements the middleware. In this case, that's bmt.auth.middleware.AuthenticationMiddleware.

 GRAPHENE = {
   # ...
    'MIDDLEWARE': ['bmt.auth.middleware.AuthenticationMiddleware',],
}

Then bmt/auth/middleware.py would look like…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by zbyte64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #1153 on April 14, 2021 19:58.