added OfflineAuthenticator

This commit is contained in:
əlemi 2022-04-18 19:31:52 +02:00
parent a2c2b78f89
commit 7789888e03
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 24 additions and 2 deletions

View file

@ -1,3 +1,3 @@
from .interface import AuthException, AuthInterface from .interface import AuthException, AuthInterface, OfflineAuthenticator
from .microsoft import MicrosoftAuthenticator from .microsoft import MicrosoftAuthenticator
from .mojang import MojangAuthenticator from .mojang import MojangAuthenticator

View file

@ -1,5 +1,6 @@
"""Minecraft authentication interface""" """Minecraft authentication interface"""
import logging import logging
from multiprocessing.sharedctypes import Value
from typing import Optional, Dict, Any from typing import Optional, Dict, Any
import aiohttp import aiohttp
@ -40,7 +41,7 @@ class AuthInterface:
def serialize(self) -> Dict[str, Any]: def serialize(self) -> Dict[str, Any]:
raise NotImplementedError raise NotImplementedError
def deserialize(self, data:Dict[str, Any]) -> 'AuthInterface': def deserialize(self, data:Dict[str, Any]):
raise NotImplementedError raise NotImplementedError
async def join(self, server_id) -> dict: async def join(self, server_id) -> dict:
@ -80,3 +81,24 @@ class AuthInterface:
if res.status >= 400: if res.status >= 400:
raise AuthException(endpoint, res.status, data, kwargs) raise AuthException(endpoint, res.status, data, kwargs)
return data return data
class OfflineAuthenticator(AuthInterface):
def __init__(self, name:str, id:str=''):
self.accessToken = ''
self.selectedProfile = GameProfile(id=id, name=name)
async def login(self) -> 'AuthInterface':
raise AuthException('login', 418, {"error":"offline authenticator cannot login"}, kwargs={})
async def refresh(self) -> 'AuthInterface':
raise AuthException('refresh', 418, {"error":"offline authenticator cannot refresh"}, kwargs={})
async def validate(self) -> 'AuthInterface':
raise AuthException('validate', 418, {"error":"offline authenticator cannot validate"}, kwargs={})
def serialize(self) -> Dict[str, Any]:
return {}
def deserialize(self, data:Dict[str, Any]) -> 'AuthInterface':
pass