set firebase key with checkin
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
parent
76498a2d7b
commit
90606fabf9
|
@ -47,16 +47,16 @@ class MobileDeviceSerializer(DeviceSerializer):
|
|||
depth = 2
|
||||
|
||||
|
||||
class MobileDeviceCheckInSerializer(PassiveSerializer):
|
||||
"""Check info into authentik"""
|
||||
|
||||
info = MobileDeviceInfoSerializer()
|
||||
|
||||
|
||||
class MobileDeviceSetPushKeySerializer(PassiveSerializer):
|
||||
"""Set notification key"""
|
||||
|
||||
firebase_key = CharField(required=True)
|
||||
firebase_key = CharField(required=False)
|
||||
|
||||
|
||||
class MobileDeviceCheckInSerializer(MobileDeviceSetPushKeySerializer):
|
||||
"""Check info into authentik"""
|
||||
|
||||
info = MobileDeviceInfoSerializer()
|
||||
|
||||
|
||||
class MobileDeviceEnrollmentSerializer(MobileDeviceSetPushKeySerializer):
|
||||
|
@ -128,6 +128,7 @@ class MobileDeviceViewSet(
|
|||
new_token = MobileDeviceToken.objects.create(
|
||||
device=device,
|
||||
user=device.user,
|
||||
expiring=False,
|
||||
)
|
||||
return Response(
|
||||
data={
|
||||
|
@ -163,28 +164,6 @@ class MobileDeviceViewSet(
|
|||
device: MobileDevice = self.get_object()
|
||||
return Response({"status": "success" if device.confirmed else "waiting"})
|
||||
|
||||
@extend_schema(
|
||||
responses={
|
||||
204: OpenApiResponse(description="Key successfully set"),
|
||||
},
|
||||
request=MobileDeviceSetPushKeySerializer,
|
||||
)
|
||||
@action(
|
||||
methods=["POST"],
|
||||
detail=True,
|
||||
permission_classes=[],
|
||||
filter_backends=[],
|
||||
authentication_classes=[MobileDeviceTokenAuthentication],
|
||||
)
|
||||
def set_notification_key(self, request: Request, pk: str) -> Response:
|
||||
"""Called by the phone whenever the firebase key changes and we need to update it"""
|
||||
device: MobileDevice = self.get_object()
|
||||
data = MobileDeviceSetPushKeySerializer(data=request.data)
|
||||
data.is_valid(raise_exception=True)
|
||||
device.firebase_token = data.validated_data["firebase_key"]
|
||||
device.save()
|
||||
return Response(status=204)
|
||||
|
||||
@extend_schema(
|
||||
responses={
|
||||
204: OpenApiResponse(description="Key successfully set"),
|
||||
|
@ -214,7 +193,7 @@ class MobileDeviceViewSet(
|
|||
responses={
|
||||
204: OpenApiResponse(description="Checked in"),
|
||||
},
|
||||
request=MobileDeviceInfoSerializer,
|
||||
request=MobileDeviceCheckInSerializer,
|
||||
)
|
||||
@action(
|
||||
methods=["POST"],
|
||||
|
@ -225,11 +204,12 @@ class MobileDeviceViewSet(
|
|||
)
|
||||
def check_in(self, request: Request, pk: str) -> Response:
|
||||
"""Check in data about a device"""
|
||||
data = MobileDeviceInfoSerializer(data=request.data)
|
||||
data = MobileDeviceCheckInSerializer(data=request.data)
|
||||
data.is_valid(raise_exception=True)
|
||||
device: MobileDevice = self.get_object()
|
||||
device.last_checkin = now()
|
||||
device.state = data.validated_data
|
||||
device.state = data.validated_data["info"]
|
||||
device.firebase_token = data.validated_data["firebase_key"]
|
||||
device.save()
|
||||
return Response(status=204)
|
||||
|
||||
|
|
61
schema.yml
61
schema.yml
|
@ -2183,7 +2183,7 @@ paths:
|
|||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/MobileDeviceInfoRequest'
|
||||
$ref: '#/components/schemas/MobileDeviceCheckInRequest'
|
||||
required: true
|
||||
security:
|
||||
- mobile_device_token: []
|
||||
|
@ -2317,44 +2317,6 @@ paths:
|
|||
schema:
|
||||
$ref: '#/components/schemas/GenericError'
|
||||
description: ''
|
||||
/authenticators/mobile/{uuid}/set_notification_key/:
|
||||
post:
|
||||
operationId: authenticators_mobile_set_notification_key_create
|
||||
description: Called by the phone whenever the firebase key changes and we need
|
||||
to update it
|
||||
parameters:
|
||||
- in: path
|
||||
name: uuid
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
description: A UUID string identifying this Mobile Device.
|
||||
required: true
|
||||
tags:
|
||||
- authenticators
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/MobileDeviceSetPushKeyRequest'
|
||||
required: true
|
||||
security:
|
||||
- mobile_device_token: []
|
||||
responses:
|
||||
'204':
|
||||
description: Key successfully set
|
||||
'400':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ValidationError'
|
||||
description: ''
|
||||
'403':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GenericError'
|
||||
description: ''
|
||||
/authenticators/mobile/{uuid}/used_by/:
|
||||
get:
|
||||
operationId: authenticators_mobile_used_by_list
|
||||
|
@ -35369,6 +35331,17 @@ components:
|
|||
- type
|
||||
- verbose_name
|
||||
- verbose_name_plural
|
||||
MobileDeviceCheckInRequest:
|
||||
type: object
|
||||
description: Check info into authentik
|
||||
properties:
|
||||
firebase_key:
|
||||
type: string
|
||||
minLength: 1
|
||||
info:
|
||||
$ref: '#/components/schemas/MobileDeviceInfoRequest'
|
||||
required:
|
||||
- info
|
||||
MobileDeviceEnrollmentCallback:
|
||||
type: object
|
||||
properties:
|
||||
|
@ -35390,7 +35363,6 @@ components:
|
|||
$ref: '#/components/schemas/MobileDeviceInfoRequest'
|
||||
required:
|
||||
- device_uid
|
||||
- firebase_key
|
||||
- info
|
||||
MobileDeviceEnrollmentStatus:
|
||||
type: object
|
||||
|
@ -35481,15 +35453,6 @@ components:
|
|||
required:
|
||||
- selected_item
|
||||
- tx_id
|
||||
MobileDeviceSetPushKeyRequest:
|
||||
type: object
|
||||
description: Set notification key
|
||||
properties:
|
||||
firebase_key:
|
||||
type: string
|
||||
minLength: 1
|
||||
required:
|
||||
- firebase_key
|
||||
ModelEnum:
|
||||
enum:
|
||||
- authentik_crypto.certificatekeypair
|
||||
|
|
|
@ -227,7 +227,7 @@ paths:
|
|||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/MobileDeviceInfoRequest'
|
||||
$ref: '#/components/schemas/MobileDeviceCheckInRequest'
|
||||
required: true
|
||||
security:
|
||||
- mobile_device_token: []
|
||||
|
@ -361,44 +361,6 @@ paths:
|
|||
schema:
|
||||
$ref: '#/components/schemas/GenericError'
|
||||
description: ''
|
||||
/authenticators/mobile/{uuid}/set_notification_key/:
|
||||
post:
|
||||
operationId: authenticators_mobile_set_notification_key_create
|
||||
description: Called by the phone whenever the firebase key changes and we need
|
||||
to update it
|
||||
parameters:
|
||||
- in: path
|
||||
name: uuid
|
||||
schema:
|
||||
type: string
|
||||
format: uuid
|
||||
description: A UUID string identifying this Mobile Device.
|
||||
required: true
|
||||
tags:
|
||||
- authenticators
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/MobileDeviceSetPushKeyRequest'
|
||||
required: true
|
||||
security:
|
||||
- mobile_device_token: []
|
||||
responses:
|
||||
'204':
|
||||
description: Key successfully set
|
||||
'400':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ValidationError'
|
||||
description: ''
|
||||
'403':
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/GenericError'
|
||||
description: ''
|
||||
/authenticators/mobile/{uuid}/used_by/:
|
||||
get:
|
||||
operationId: authenticators_mobile_used_by_list
|
||||
|
@ -500,6 +462,17 @@ components:
|
|||
- type
|
||||
- verbose_name
|
||||
- verbose_name_plural
|
||||
MobileDeviceCheckInRequest:
|
||||
type: object
|
||||
description: Check info into authentik
|
||||
properties:
|
||||
firebase_key:
|
||||
type: string
|
||||
minLength: 1
|
||||
info:
|
||||
$ref: '#/components/schemas/MobileDeviceInfoRequest'
|
||||
required:
|
||||
- info
|
||||
MobileDeviceEnrollmentCallback:
|
||||
type: object
|
||||
properties:
|
||||
|
@ -521,7 +494,6 @@ components:
|
|||
$ref: '#/components/schemas/MobileDeviceInfoRequest'
|
||||
required:
|
||||
- device_uid
|
||||
- firebase_key
|
||||
- info
|
||||
MobileDeviceEnrollmentStatus:
|
||||
type: object
|
||||
|
@ -604,15 +576,6 @@ components:
|
|||
required:
|
||||
- selected_item
|
||||
- tx_id
|
||||
MobileDeviceSetPushKeyRequest:
|
||||
type: object
|
||||
description: Set notification key
|
||||
properties:
|
||||
firebase_key:
|
||||
type: string
|
||||
minLength: 1
|
||||
required:
|
||||
- firebase_key
|
||||
PaginatedMobileDeviceList:
|
||||
type: object
|
||||
properties:
|
||||
|
|
Reference in New Issue