-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add endpoint to query auth details in MitmReceivers
- Loading branch information
Showing
2 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |