SDK-2526: Refactor authentication

This commit is contained in:
Romuald Juchnowicz-Bierbasz
2019-02-12 17:55:28 +01:00
parent 00fe3dd553
commit 0d52b3dda6
4 changed files with 6 additions and 18 deletions

View File

@@ -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()

View File

@@ -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 = {

View File

@@ -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",

View File

@@ -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()