|
5 | 5 | from django_rq.queues import get_connection |
6 | 6 | from drf_spectacular.types import OpenApiTypes |
7 | 7 | from drf_spectacular.utils import extend_schema |
| 8 | +from rest_framework.permissions import IsAuthenticated |
8 | 9 | from rest_framework.response import Response |
9 | 10 | from rest_framework.reverse import reverse |
10 | 11 | from rest_framework.views import APIView |
11 | 12 | from rq.worker import Worker |
12 | 13 |
|
13 | 14 | from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired |
14 | 15 | from netbox.plugins.utils import get_installed_plugins |
| 16 | +from users.api.serializers import UserSerializer |
15 | 17 | from utilities.apps import get_installed_apps |
16 | 18 |
|
17 | 19 |
|
@@ -62,3 +64,15 @@ def get(self, request): |
62 | 64 | 'python-version': platform.python_version(), |
63 | 65 | 'rq-workers-running': Worker.count(get_connection('default')), |
64 | 66 | }) |
| 67 | + |
| 68 | + |
| 69 | +class AuthenticationCheckView(APIView): |
| 70 | + """ |
| 71 | + Return the user making the request, if authenticated successfully. |
| 72 | + """ |
| 73 | + permission_classes = [IsAuthenticated] |
| 74 | + |
| 75 | + @extend_schema(responses={200: OpenApiTypes.OBJECT}) |
| 76 | + def get(self, request): |
| 77 | + serializer = UserSerializer(request.user, context={'request': request}) |
| 78 | + return Response(serializer.data) |
0 commit comments