fix geoip usage

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2024-01-02 22:59:23 +01:00
parent e425eaee1f
commit c90d35b113
No known key found for this signature in database
3 changed files with 18 additions and 25 deletions

View File

@ -177,6 +177,14 @@ class MobileTransaction(ExpiringModel):
user: User = self.device.user user: User = self.device.user
client_ip = ClientIPMiddleware.get_client_ip(request) 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( auth_request = AuthenticationRequest(
device_token=self.device.firebase_token, device_token=self.device.firebase_token,
tx_id=str(self.tx_id), tx_id=str(self.tx_id),
@ -192,17 +200,10 @@ class MobileTransaction(ExpiringModel):
} }
), ),
client_ip=client_ip, client_ip=client_ip,
geo=AuthenticationRequest.Attributes.Geo(), geo=geo,
extra=context, 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) client = get_client(self.device.stage.cgw_endpoint)
try: try:
response = client.SendRequest(auth_request) response = client.SendRequest(auth_request)

View File

@ -35356,16 +35356,16 @@ components:
confirmed: confirmed:
type: boolean type: boolean
readOnly: true readOnly: true
last_checkin: state:
allOf: allOf:
- $ref: '#/components/schemas/MobileDeviceInfo' - $ref: '#/components/schemas/MobileDeviceInfo'
readOnly: true readOnly: true
required: required:
- confirmed - confirmed
- last_checkin
- meta_model_name - meta_model_name
- name - name
- pk - pk
- state
- type - type
- verbose_name - verbose_name
- verbose_name_plural - verbose_name_plural
@ -35417,9 +35417,7 @@ components:
type: string type: string
app_version: app_version:
type: string type: string
others: others: {}
type: object
additionalProperties: {}
required: required:
- app_version - app_version
- hostname - hostname
@ -35445,9 +35443,7 @@ components:
app_version: app_version:
type: string type: string
minLength: 1 minLength: 1
others: others: {}
type: object
additionalProperties: {}
required: required:
- app_version - app_version
- hostname - hostname

View File

@ -1,7 +1,7 @@
openapi: 3.0.3 openapi: 3.0.3
info: info:
title: authentik title: authentik
version: 2023.10.4 version: 2023.10.5
description: Making authentication simple. description: Making authentication simple.
contact: contact:
email: hello@goauthentik.io email: hello@goauthentik.io
@ -487,16 +487,16 @@ components:
confirmed: confirmed:
type: boolean type: boolean
readOnly: true readOnly: true
last_checkin: state:
allOf: allOf:
- $ref: '#/components/schemas/MobileDeviceInfo' - $ref: '#/components/schemas/MobileDeviceInfo'
readOnly: true readOnly: true
required: required:
- confirmed - confirmed
- last_checkin
- meta_model_name - meta_model_name
- name - name
- pk - pk
- state
- type - type
- verbose_name - verbose_name
- verbose_name_plural - verbose_name_plural
@ -540,9 +540,7 @@ components:
type: string type: string
app_version: app_version:
type: string type: string
others: others: {}
type: object
additionalProperties: {}
required: required:
- app_version - app_version
- hostname - hostname
@ -568,9 +566,7 @@ components:
app_version: app_version:
type: string type: string
minLength: 1 minLength: 1
others: others: {}
type: object
additionalProperties: {}
required: required:
- app_version - app_version
- hostname - hostname