Skip to content

Instantly share code, notes, and snippets.

View tshrv's full-sized avatar

Tushar Srivastava tshrv

View GitHub Profile
@AliRn76
AliRn76 / Django_Channels3_Custom_Auth_Middleware.py
Last active April 10, 2025 16:38
Token authorization middleware for Django Channels 3
from django.contrib.auth.models import AnonymousUser
from rest_framework.authtoken.models import Token
from channels.db import database_sync_to_async
from channels.middleware import BaseMiddleware
from project.settings import SIMPLE_JWT, SECRET_KEY
@database_sync_to_async
def get_user(token_key):
# If you are using normal token based authentication
try: