revert to old method of checking

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-12-17 23:40:50 +01:00
parent 3c59a60152
commit 02cfc80b9f
No known key found for this signature in database
1 changed files with 12 additions and 21 deletions

View File

@ -1,14 +1,10 @@
"""Mobile authenticator stage""" """Mobile authenticator stage"""
from secrets import choice from secrets import choice
from time import sleep
from typing import Optional from typing import Optional
from uuid import uuid4 from uuid import uuid4
from authentik_cloud_gateway_client.authenticationPush_pb2 import ( from authentik_cloud_gateway_client.authenticationPush_pb2 import AuthenticationRequest
AuthenticationCheckRequest,
AuthenticationRequest,
AuthenticationResponse,
AuthenticationResponseStatus,
)
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.db import models from django.db import models
from django.http import HttpRequest from django.http import HttpRequest
@ -206,22 +202,17 @@ class MobileTransaction(ExpiringModel):
def wait_for_response(self, max_checks=30) -> TransactionStates: def wait_for_response(self, max_checks=30) -> TransactionStates:
"""Wait for a change in status""" """Wait for a change in status"""
client = get_client(self.device.stage.cgw_endpoint) checks = 0
for response in client.CheckStatus( while True:
AuthenticationCheckRequest(tx_id=self.tx_id, attempts=max_checks) self.refresh_from_db()
).next(): if self.status in [TransactionStates.ACCEPT, TransactionStates.DENY]:
response: AuthenticationResponse self.delete()
if response.status == AuthenticationResponseStatus.ANSWERED: return self.status
self.selected_item = response.decided_item checks += 1
self.save() if checks > max_checks:
elif response.status == AuthenticationResponseStatus.FAILED: self.delete()
raise TimeoutError() raise TimeoutError()
elif response.status in [ sleep(1)
AuthenticationResponseStatus.UNKNOWN,
AuthenticationResponseStatus.SENT,
]:
continue
self.delete()
class MobileDeviceToken(ExpiringModel): class MobileDeviceToken(ExpiringModel):