From dab165396d41385746f3a505ed6577a13bc95713 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 25 Oct 2023 11:48:11 +0800 Subject: [PATCH] bugfix --- ahserver/auth_api.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ahserver/auth_api.py b/ahserver/auth_api.py index aa22f7d..1476c78 100755 --- a/ahserver/auth_api.py +++ b/ahserver/auth_api.py @@ -15,6 +15,13 @@ from appPublic.jsonConfig import getConfig from appPublic.rsawrap import RSA from appPublic.app_logger import AppLogger +def get_client_ip(obj, request): + ip = request.headers.get('X-Forwarded-For') + if not ip: + ip = request.remote + request['client_ip'] = ip + return ip + class AuthAPI(AppLogger): def __init__(self): super().__init__() @@ -35,13 +42,6 @@ class AuthAPI(AppLogger): self.getPrivateKey() return self.rsaEngine.decode(self.privatekey,cdata) - def get_client_ip(self, request): - ip = request.headers.get('X-Forwarded-For') - if not ip: - ip = request.remote - request['client_ip'] = ip - return ip - async def setupAuth(self,app): # setup session middleware in aiohttp fashion @@ -65,14 +65,14 @@ class AuthAPI(AppLogger): def _new_ticket(self, request, user_id): client_uuid = request.headers.get('client_uuid') - ip = self.get_client_ip(request) + ip = self._get_ip(request) if not ip: ip = request.remote valid_until = int(time.time()) + self._max_age print(f'hack: my _new_ticket() called ...remote {ip=}, {client_uuid=}') return self._ticket.new(user_id, valid_until=valid_until, client_ip=ip, user_data=client_uuid) - TktAuthentication._get_ip = self.get_client_ip + TktAuthentication._get_ip = get_client_ip TktAuthentication._new_ticket = _new_ticket policy = auth.SessionTktAuthentication(urandom(32), session_max_time, reissue_time=session_reissue_time, @@ -92,7 +92,7 @@ class AuthAPI(AppLogger): user = await auth.get_auth(request) is_ok = await self.checkUserPermission(user, path) t2 = time.time() - ip = self.get_client_ip(request) + ip = get_client_ip(None, request) if is_ok: try: ret = await handler(request)