django-grpc icon indicating copy to clipboard operation
django-grpc copied to clipboard

how to implements django auth

Open yswtrue opened this issue 5 years ago • 2 comments

yswtrue avatar Aug 16 '20 13:08 yswtrue

It would be great to integrate with django authentication system. Feel free to open pull request

gluk-w avatar Aug 17 '20 23:08 gluk-w

One super simple way is to create an auth wrapper and wrap the methods that require it

from django.http import HttpRequest
from django.contrib.auth.middleware import AuthenticationMiddleware

class requires_authentication(object):

    def __call__(self, f):
        async def authenticate(s, stream):
            request = HttpRequest()
            request.META = dict(stream.metadata)
            AuthenticationMiddleware.process_request(request)
            return await f(s, stream)

        return authenticate

dashdanw avatar Dec 15 '20 08:12 dashdanw