I currently have the problem, that I need different authentication mechanisms for different Django Channel consumers. One of them should use a custom token middleware while the other should use the standard session-based authentication. How can it be achieved that middlewares can be applied per path?
In the standard Django views this is achieved with def process_view(self, request, view_func, view_args, view_kwargs):
as shown in this answer.
# routing.py
application = ProtocolTypeRouter(
{
"http": get_asgi_application(),
"websocket": TokenAuthMiddleware(
URLRouter(
[
path(
"ws-api/v1/farms/controllers/",
ControllerConsumer.as_asgi(),
name="ws-controller",
),
path("ws-api/v1/graphql/", MyGraphqlWsConsumer.as_asgi()),
]
)
)
}
)