From c90d35b113692a843399a2c39d45e97d772e0a4a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 2 Jan 2024 22:59:23 +0100 Subject: [PATCH] fix geoip usage Signed-off-by: Jens Langhammer --- authentik/stages/authenticator_mobile/models.py | 17 +++++++++-------- schema.yml | 12 ++++-------- schemas/authentik-cloud-gateway.yml | 14 +++++--------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/authentik/stages/authenticator_mobile/models.py b/authentik/stages/authenticator_mobile/models.py index a1d2f7415..24d492ae6 100644 --- a/authentik/stages/authenticator_mobile/models.py +++ b/authentik/stages/authenticator_mobile/models.py @@ -177,6 +177,14 @@ class MobileTransaction(ExpiringModel): user: User = self.device.user client_ip = ClientIPMiddleware.get_client_ip(request) + geo = None + if GEOIP_CONTEXT_PROCESSOR.configured(): + city = GEOIP_CONTEXT_PROCESSOR.city(client_ip) + if city: + geo = AuthenticationRequest.Attributes.Geo( + lat=city.location.latitude, + long=city.location.longitude, + ) auth_request = AuthenticationRequest( device_token=self.device.firebase_token, tx_id=str(self.tx_id), @@ -192,17 +200,10 @@ class MobileTransaction(ExpiringModel): } ), client_ip=client_ip, - geo=AuthenticationRequest.Attributes.Geo(), + geo=geo, extra=context, ), ) - if GEOIP_CONTEXT_PROCESSOR.configured(): - geo = GEOIP_CONTEXT_PROCESSOR.city(client_ip) - if geo: - auth_request.attributes.geo = AuthenticationRequest.Attributes.Geo( - lat=geo.location.latitude, - long=geo.location.longitude, - ) client = get_client(self.device.stage.cgw_endpoint) try: response = client.SendRequest(auth_request) diff --git a/schema.yml b/schema.yml index a15b9449e..dc4247099 100644 --- a/schema.yml +++ b/schema.yml @@ -35356,16 +35356,16 @@ components: confirmed: type: boolean readOnly: true - last_checkin: + state: allOf: - $ref: '#/components/schemas/MobileDeviceInfo' readOnly: true required: - confirmed - - last_checkin - meta_model_name - name - pk + - state - type - verbose_name - verbose_name_plural @@ -35417,9 +35417,7 @@ components: type: string app_version: type: string - others: - type: object - additionalProperties: {} + others: {} required: - app_version - hostname @@ -35445,9 +35443,7 @@ components: app_version: type: string minLength: 1 - others: - type: object - additionalProperties: {} + others: {} required: - app_version - hostname diff --git a/schemas/authentik-cloud-gateway.yml b/schemas/authentik-cloud-gateway.yml index cdb265710..ccb8ec915 100644 --- a/schemas/authentik-cloud-gateway.yml +++ b/schemas/authentik-cloud-gateway.yml @@ -1,7 +1,7 @@ openapi: 3.0.3 info: title: authentik - version: 2023.10.4 + version: 2023.10.5 description: Making authentication simple. contact: email: hello@goauthentik.io @@ -487,16 +487,16 @@ components: confirmed: type: boolean readOnly: true - last_checkin: + state: allOf: - $ref: '#/components/schemas/MobileDeviceInfo' readOnly: true required: - confirmed - - last_checkin - meta_model_name - name - pk + - state - type - verbose_name - verbose_name_plural @@ -540,9 +540,7 @@ components: type: string app_version: type: string - others: - type: object - additionalProperties: {} + others: {} required: - app_version - hostname @@ -568,9 +566,7 @@ components: app_version: type: string minLength: 1 - others: - type: object - additionalProperties: {} + others: {} required: - app_version - hostname