Skip to content

Commit

Permalink
Add endpoint to query auth details in MitmReceivers
Browse files Browse the repository at this point in the history
  • Loading branch information
Grennith committed Mar 31, 2024
1 parent 5b8f606 commit af0e1ea
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
40 changes: 40 additions & 0 deletions mapadroid/mitm_receiver/endpoints/AuthMethodEndpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from typing import List, Optional

from loguru import logger

from mapadroid.db.helper.SettingsDeviceHelper import SettingsDeviceHelper
from mapadroid.db.helper.SettingsPogoauthHelper import SettingsPogoauthHelper
from mapadroid.db.model import SettingsDevice, SettingsPogoauth
from mapadroid.mitm_receiver.endpoints.AbstractMitmReceiverRootEndpoint import \
AbstractMitmReceiverRootEndpoint


class AuthMethodEndpoint(AbstractMitmReceiverRootEndpoint):
"""
"/auth_method"
"""

# TODO: Check Origin etc auth checks using decorators or better: visitor pattern...

async def _iter(self):
# TODO: VisitorPattern for extra auth checks...
with logger.contextualize(identifier=self._get_request_address(), name="auth-method-endpoint"):
await self._check_origin_header()
return await super()._iter()

async def get(self):
origin = self.request.headers.get("Origin")
if not origin:
logger.error("Request without origin header")
return self._json_response({})
# TODO: Fetch assigned via API of AccountHandler implementation allowing for RPC
async with self._get_db_wrapper() as session, session:
device_entry: Optional[SettingsDevice] = await SettingsDeviceHelper.get_by_origin(
session, self._get_instance_id(), origin)
if not device_entry:
logger.warning("Device origin {} not found in device table", origin)
return self._json_response({})
currently_assigned: Optional[SettingsPogoauth] = await SettingsPogoauthHelper.get_assigned_to_device(
session, device_entry.device_id)
response = {"method": currently_assigned.login_type}
return self._json_response(response)
12 changes: 9 additions & 3 deletions mapadroid/mitm_receiver/endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
from aiohttp import web

from mapadroid.mitm_receiver.endpoints.GetAddressesEndpoint import GetAddressesEndpoint
from mapadroid.mitm_receiver.endpoints.GetLatestEndpoint import GetLatestEndpoint
from mapadroid.mitm_receiver.endpoints.ReceiveProtosEndpoint import ReceiveProtosEndpoint
from mapadroid.mitm_receiver.endpoints.AuthMethodEndpoint import \
AuthMethodEndpoint
from mapadroid.mitm_receiver.endpoints.GetAddressesEndpoint import \
GetAddressesEndpoint
from mapadroid.mitm_receiver.endpoints.GetLatestEndpoint import \
GetLatestEndpoint
from mapadroid.mitm_receiver.endpoints.ReceiveProtosEndpoint import \
ReceiveProtosEndpoint


def register_mitm_receiver_root_endpoints(app: web.Application):
app.router.add_view('/get_addresses', GetAddressesEndpoint, name='get_addresses')
app.router.add_view('/', ReceiveProtosEndpoint, name='receive_protos')
app.router.add_view('/get_latest_mitm', GetLatestEndpoint, name='get_latest_mitm')
app.router.add_view('/auth_method', AuthMethodEndpoint, name='auth_method')

0 comments on commit af0e1ea

Please sign in to comment.