stages/authenticator: add user field to devices (#12636)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L.
2025-01-13 15:46:39 +01:00
committed by GitHub
parent 9bb3aa0374
commit 0ffaf0393e
6 changed files with 43 additions and 4 deletions

View File

@ -12,6 +12,7 @@ from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from structlog.stdlib import get_logger from structlog.stdlib import get_logger
from authentik.core.api.groups import GroupMemberSerializer
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import ModelSerializer from authentik.core.api.utils import ModelSerializer
from authentik.flows.api.stages import StageSerializer from authentik.flows.api.stages import StageSerializer
@ -165,9 +166,11 @@ class AuthenticatorDuoStageViewSet(UsedByMixin, ModelViewSet):
class DuoDeviceSerializer(ModelSerializer): class DuoDeviceSerializer(ModelSerializer):
"""Serializer for Duo authenticator devices""" """Serializer for Duo authenticator devices"""
user = GroupMemberSerializer(read_only=True)
class Meta: class Meta:
model = DuoDevice model = DuoDevice
fields = ["pk", "name"] fields = ["pk", "name", "user"]
depth = 2 depth = 2

View File

@ -3,6 +3,7 @@
from rest_framework import mixins from rest_framework import mixins
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from authentik.core.api.groups import GroupMemberSerializer
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import ModelSerializer from authentik.core.api.utils import ModelSerializer
from authentik.flows.api.stages import StageSerializer from authentik.flows.api.stages import StageSerializer
@ -41,9 +42,11 @@ class AuthenticatorSMSStageViewSet(UsedByMixin, ModelViewSet):
class SMSDeviceSerializer(ModelSerializer): class SMSDeviceSerializer(ModelSerializer):
"""Serializer for sms authenticator devices""" """Serializer for sms authenticator devices"""
user = GroupMemberSerializer(read_only=True)
class Meta: class Meta:
model = SMSDevice model = SMSDevice
fields = ["name", "pk", "phone_number"] fields = ["name", "pk", "phone_number", "user"]
depth = 2 depth = 2
extra_kwargs = { extra_kwargs = {
"phone_number": {"read_only": True}, "phone_number": {"read_only": True},

View File

@ -3,6 +3,7 @@
from rest_framework import mixins from rest_framework import mixins
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from authentik.core.api.groups import GroupMemberSerializer
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import ModelSerializer from authentik.core.api.utils import ModelSerializer
from authentik.flows.api.stages import StageSerializer from authentik.flows.api.stages import StageSerializer
@ -48,10 +49,11 @@ class StaticDeviceSerializer(ModelSerializer):
"""Serializer for static authenticator devices""" """Serializer for static authenticator devices"""
token_set = StaticDeviceTokenSerializer(many=True, read_only=True) token_set = StaticDeviceTokenSerializer(many=True, read_only=True)
user = GroupMemberSerializer(read_only=True)
class Meta: class Meta:
model = StaticDevice model = StaticDevice
fields = ["name", "token_set", "pk"] fields = ["name", "token_set", "pk", "user"]
class StaticDeviceViewSet( class StaticDeviceViewSet(

View File

@ -4,6 +4,7 @@ from rest_framework import mixins
from rest_framework.fields import ChoiceField from rest_framework.fields import ChoiceField
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from authentik.core.api.groups import GroupMemberSerializer
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import ModelSerializer from authentik.core.api.utils import ModelSerializer
from authentik.flows.api.stages import StageSerializer from authentik.flows.api.stages import StageSerializer
@ -37,11 +38,14 @@ class AuthenticatorTOTPStageViewSet(UsedByMixin, ModelViewSet):
class TOTPDeviceSerializer(ModelSerializer): class TOTPDeviceSerializer(ModelSerializer):
"""Serializer for totp authenticator devices""" """Serializer for totp authenticator devices"""
user = GroupMemberSerializer(read_only=True)
class Meta: class Meta:
model = TOTPDevice model = TOTPDevice
fields = [ fields = [
"name", "name",
"pk", "pk",
"user",
] ]
depth = 2 depth = 2

View File

@ -3,6 +3,7 @@
from rest_framework import mixins from rest_framework import mixins
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from authentik.core.api.groups import GroupMemberSerializer
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import ModelSerializer from authentik.core.api.utils import ModelSerializer
from authentik.stages.authenticator_webauthn.api.device_types import WebAuthnDeviceTypeSerializer from authentik.stages.authenticator_webauthn.api.device_types import WebAuthnDeviceTypeSerializer
@ -13,10 +14,11 @@ class WebAuthnDeviceSerializer(ModelSerializer):
"""Serializer for WebAuthn authenticator devices""" """Serializer for WebAuthn authenticator devices"""
device_type = WebAuthnDeviceTypeSerializer(read_only=True, allow_null=True) device_type = WebAuthnDeviceTypeSerializer(read_only=True, allow_null=True)
user = GroupMemberSerializer(read_only=True)
class Meta: class Meta:
model = WebAuthnDevice model = WebAuthnDevice
fields = ["pk", "name", "created_on", "device_type", "aaguid"] fields = ["pk", "name", "created_on", "device_type", "aaguid", "user"]
extra_kwargs = { extra_kwargs = {
"aaguid": {"read_only": True}, "aaguid": {"read_only": True},
} }

View File

@ -41226,9 +41226,14 @@ components:
type: string type: string
description: The human-readable name of this device. description: The human-readable name of this device.
maxLength: 64 maxLength: 64
user:
allOf:
- $ref: '#/components/schemas/GroupMember'
readOnly: true
required: required:
- name - name
- pk - pk
- user
DuoDeviceEnrollmentStatus: DuoDeviceEnrollmentStatus:
type: object type: object
properties: properties:
@ -54570,10 +54575,15 @@ components:
phone_number: phone_number:
type: string type: string
readOnly: true readOnly: true
user:
allOf:
- $ref: '#/components/schemas/GroupMember'
readOnly: true
required: required:
- name - name
- phone_number - phone_number
- pk - pk
- user
SMSDeviceRequest: SMSDeviceRequest:
type: object type: object
description: Serializer for sms authenticator devices description: Serializer for sms authenticator devices
@ -55275,10 +55285,15 @@ components:
type: integer type: integer
readOnly: true readOnly: true
title: ID title: ID
user:
allOf:
- $ref: '#/components/schemas/GroupMember'
readOnly: true
required: required:
- name - name
- pk - pk
- token_set - token_set
- user
StaticDeviceRequest: StaticDeviceRequest:
type: object type: object
description: Serializer for static authenticator devices description: Serializer for static authenticator devices
@ -55507,9 +55522,14 @@ components:
type: integer type: integer
readOnly: true readOnly: true
title: ID title: ID
user:
allOf:
- $ref: '#/components/schemas/GroupMember'
readOnly: true
required: required:
- name - name
- pk - pk
- user
TOTPDeviceRequest: TOTPDeviceRequest:
type: object type: object
description: Serializer for totp authenticator devices description: Serializer for totp authenticator devices
@ -56951,12 +56971,17 @@ components:
aaguid: aaguid:
type: string type: string
readOnly: true readOnly: true
user:
allOf:
- $ref: '#/components/schemas/GroupMember'
readOnly: true
required: required:
- aaguid - aaguid
- created_on - created_on
- device_type - device_type
- name - name
- pk - pk
- user
WebAuthnDeviceRequest: WebAuthnDeviceRequest:
type: object type: object
description: Serializer for WebAuthn authenticator devices description: Serializer for WebAuthn authenticator devices