diff --git a/authentik/core/api/tokens.py b/authentik/core/api/tokens.py index 6b42f85c8..db07f4c9d 100644 --- a/authentik/core/api/tokens.py +++ b/authentik/core/api/tokens.py @@ -11,7 +11,7 @@ from rest_framework.viewsets import ModelViewSet from authentik.api.decorators import permission_required from authentik.core.api.users import UserSerializer from authentik.core.api.utils import PassiveSerializer -from authentik.core.models import Token +from authentik.core.models import Token, TokenIntents from authentik.events.models import Event, EventAction from authentik.managed.api import ManagedSerializer @@ -64,7 +64,7 @@ class TokenViewSet(ModelViewSet): ordering = ["expires"] def perform_create(self, serializer: TokenSerializer): - serializer.save(user=self.request.user) + serializer.save(user=self.request.user, intent=TokenIntents.INTENT_API) @permission_required("authentik_core.view_token_key") @swagger_auto_schema( diff --git a/authentik/core/tests/test_token_api.py b/authentik/core/tests/test_token_api.py index 5588bc527..a1c994446 100644 --- a/authentik/core/tests/test_token_api.py +++ b/authentik/core/tests/test_token_api.py @@ -2,7 +2,7 @@ from django.urls.base import reverse from rest_framework.test import APITestCase -from authentik.core.models import Token, User +from authentik.core.models import Token, TokenIntents, User class TestTokenAPI(APITestCase): @@ -19,4 +19,6 @@ class TestTokenAPI(APITestCase): reverse("authentik_api:token-list"), {"identifier": "test-token"} ) self.assertEqual(response.status_code, 201) - self.assertEqual(Token.objects.get(identifier="test-token").user, self.user) + token = Token.objects.get(identifier="test-token") + self.assertEqual(token.user, self.user) + self.assertEqual(token.intent, TokenIntents.INTENT_API)