From 0d52b3dda66533b57f29fa8139c0d8b0a9009bd5 Mon Sep 17 00:00:00 2001 From: Romuald Juchnowicz-Bierbasz Date: Tue, 12 Feb 2019 17:55:28 +0100 Subject: [PATCH] SDK-2526: Refactor authentication --- galaxy/api/plugin.py | 10 ++-------- galaxy/api/types.py | 7 +------ tests/conftest.py | 1 - tests/test_authenticate.py | 6 +++--- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/galaxy/api/plugin.py b/galaxy/api/plugin.py index f2b8bbb..273ff69 100644 --- a/galaxy/api/plugin.py +++ b/galaxy/api/plugin.py @@ -44,7 +44,6 @@ class Plugin(): # implemented by developer self._register_method("init_authentication", self.authenticate) - self._register_method("pass_login_credentials", self.pass_login_credentials) self._register_method( "import_owned_games", self.get_owned_games, @@ -255,16 +254,11 @@ class Plugin(): # methods async def authenticate(self, stored_credentials=None): """Overide this method to handle plugin authentication. - The method should return one of: - - galaxy.api.types.AuthenticationSuccess - on successful authencication - - galaxy.api.types.NextStep - when more authentication steps are required - Or raise galaxy.api.types.LoginError on authentication failure. + The method should return galaxy.api.types.Authentication + or raise galaxy.api.types.LoginError on authentication failure. """ raise NotImplementedError() - async def pass_login_credentials(self, step, credentials): - raise NotImplementedError() - async def get_owned_games(self): raise NotImplementedError() diff --git a/galaxy/api/types.py b/galaxy/api/types.py index 3633edf..899f682 100644 --- a/galaxy/api/types.py +++ b/galaxy/api/types.py @@ -5,15 +5,10 @@ from galaxy.api.jsonrpc import ApplicationError from galaxy.api.consts import LocalGameState, PresenceState @dataclass -class AuthenticationSuccess(): +class Authentication(): user_id: str user_name: str -@dataclass -class NextStep(): - next_step: str - auth_params: dict - class LoginError(ApplicationError): def __init__(self, current_step, reason): data = { diff --git a/tests/conftest.py b/tests/conftest.py index 589b5f1..a3d9d53 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,6 @@ def plugin(): """Return plugin instance with all feature methods mocked""" async_methods = ( "authenticate", - "pass_login_credentials", "get_owned_games", "get_unlocked_achievements", "get_local_games", diff --git a/tests/test_authenticate.py b/tests/test_authenticate.py index 24006e8..c12266d 100644 --- a/tests/test_authenticate.py +++ b/tests/test_authenticate.py @@ -1,7 +1,7 @@ import asyncio import json -from galaxy.api.types import AuthenticationSuccess, LoginError +from galaxy.api.types import Authentication, LoginError def test_success(plugin, readline, write): request = { @@ -11,7 +11,7 @@ def test_success(plugin, readline, write): } readline.side_effect = [json.dumps(request), ""] - plugin.authenticate.return_value = AuthenticationSuccess("132", "Zenek") + plugin.authenticate.return_value = Authentication("132", "Zenek") asyncio.run(plugin.run()) plugin.authenticate.assert_called_with() response = json.loads(write.call_args[0][0]) @@ -63,7 +63,7 @@ def test_stored_credentials(plugin, readline, write): } } readline.side_effect = [json.dumps(request), ""] - plugin.authenticate.return_value = AuthenticationSuccess("132", "Zenek") + plugin.authenticate.return_value = Authentication("132", "Zenek") asyncio.run(plugin.run()) plugin.authenticate.assert_called_with(stored_credentials={"token": "ABC"}) write.assert_called()