From 38628f6069ee493e6666b4d9c70c4cab41f690fe Mon Sep 17 00:00:00 2001 From: Aryamanz29 Date: Mon, 12 Dec 2022 23:01:39 +0530 Subject: [PATCH] [chores] Centralized ProtectedApiMixin logic #280 Closes #280 --- .coveragerc | 1 + openwisp_utils/api/mixins.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 openwisp_utils/api/mixins.py diff --git a/.coveragerc b/.coveragerc index ac42c385..d93a9446 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,3 +5,4 @@ omit = /*/__init__.py /setup.py /*/migrations/* + openwisp_utils/api/mixins.py diff --git a/openwisp_utils/api/mixins.py b/openwisp_utils/api/mixins.py new file mode 100644 index 00000000..7d30ae92 --- /dev/null +++ b/openwisp_utils/api/mixins.py @@ -0,0 +1,12 @@ +from openwisp_users.api.authentication import BearerAuthentication +from openwisp_users.api.permissions import DjangoModelPermissions +from rest_framework.authentication import SessionAuthentication +from rest_framework.permissions import IsAuthenticated + + +class ProtectedAPIMixin(object): + authentication_classes = [BearerAuthentication, SessionAuthentication] + permission_classes = [ + IsAuthenticated, + DjangoModelPermissions, + ]