Skip to content

Instantly share code, notes, and snippets.

View alex-pobeditel-2004's full-sized avatar

alex-pobeditel-2004

  • Mother Russia
View GitHub Profile
@alex-pobeditel-2004
alex-pobeditel-2004 / channels_jwt_middleware.py
Last active May 24, 2022 13:47
JWT Auth middleware for Django Channels 3.0 and rest_framework_simplejwt - update of @dmwyatt gist
"""
Original gist: https://gist.github.com/dmwyatt/5cf7e5102ed0a01b7d38aabf322e03b2
"""
import logging
from typing import Awaitable, Final, List, TYPE_CHECKING, TypedDict
from channels.auth import AuthMiddlewareStack
from channels.db import database_sync_to_async
from django.contrib.auth.models import AnonymousUser