add temporary firebase

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-09-04 16:23:07 +02:00
parent 1be264f1c0
commit 742b946caf
No known key found for this signature in database
4 changed files with 69 additions and 1 deletions

View File

@ -1,6 +1,7 @@
"""Mobile authenticator stage"""
from typing import Optional
from uuid import uuid4
from firebase_admin.messaging import Message, send
from django.contrib.auth import get_user_model
from django.db import models
@ -77,6 +78,22 @@ class MobileDevice(SerializerModel, Device):
return MobileDeviceSerializer
def send_message(self):
# See documentation on defining a message payload.
message = Message(
data={
'score': '850',
'time': '2:45',
},
token=self.firebase_token,
)
# Send a message to the device corresponding to the provided
# registration token.
response = send(message)
# Response is a message ID string.
print('Successfully sent message:', response)
def __str__(self):
return str(self.name) or str(self.user)

View File

@ -51,7 +51,7 @@ class AuthenticatorMobileStageView(ChallengeStageView):
confirmed=False,
)
token = MobileDeviceToken.objects.create(
user=self.get_pending_user(),
user=device.user,
device=device,
)
self.executor.plan.context[FLOW_PLAN_MOBILE_ENROLL] = token

View File

@ -177,6 +177,7 @@ wsproto = "*"
xmlsec = "*"
zxcvbn = "*"
jsonpatch = "*"
firebase-admin = "*"
[tool.poetry.dev-dependencies]
bandit = "*"

View File

@ -2206,6 +2206,41 @@ paths:
schema:
$ref: '#/components/schemas/GenericError'
description: ''
/authenticators/mobile/{uuid}/enrollment_status/:
post:
operationId: authenticators_mobile_enrollment_status_create
description: Check device enrollment status
parameters:
- in: path
name: uuid
schema:
type: string
format: uuid
description: A UUID string identifying this Mobile Device.
required: true
tags:
- authenticators
security:
- mobile_device_token: []
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/MobileDeviceEnrollmentStatus'
description: ''
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
description: ''
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/GenericError'
description: ''
/authenticators/mobile/{uuid}/receive_response/:
post:
operationId: authenticators_mobile_receive_response_create
@ -35235,6 +35270,21 @@ components:
minLength: 1
required:
- device_uid
MobileDeviceEnrollmentStatus:
type: object
properties:
status:
$ref: '#/components/schemas/MobileDeviceEnrollmentStatusStatusEnum'
required:
- status
MobileDeviceEnrollmentStatusStatusEnum:
enum:
- success
- waiting
type: string
description: |-
* `success` - Success
* `waiting` - Waiting
MobileDeviceRequest:
type: object
description: Serializer for Mobile authenticator devices