Permissions
Permissions can be applied to AsyncAPIConsumer
and its subclasses, such as GenericAsyncAPIConsumer.
This is done by setting the permission_classes = [TestPermission] property of the consumer.
from djangochannelsrestframework.consumers import AsyncAPIConsumer
from djangochannelsrestframework.permissions import IsAuthenticated
class RoomConsumer(AsyncAPIConsumer):
permission_classes = [IsAuthenticated]
You can also combine permission classes using boolean operations: | & ! are the supported operations.
from djangochannelsrestframework.consumers import AsyncAPIConsumer
from djangochannelsrestframework.permissions import IsAuthenticated
class RoomConsumer(AsyncAPIConsumer):
permission_classes = [
MyCustomPermission | IsAuthenticated
]
In addition to subclassing BasePermission You can also use any
rest_framework.permissions.BasePermission on a consumer, you may need to update your subclasses to handle the
CONNECT method, as the has_permission method is called with a proxy request using a CONNECT method string.
- class BasePermission[source]
Base permission class
Notes
You should extend this class and override the
has_permissionmethod to create your own permission class. You can also over override`can_connect` to determine if a websocket connection should even be permitted.- async has_permission (scope, consumer, action, **kwargs)