add passwordless authentication
This commit is contained in:
29
SatiAPI.py
29
SatiAPI.py
@@ -16,7 +16,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|||||||
class SatiAPI:
|
class SatiAPI:
|
||||||
"""A API wrapper for Satisfactory dedicated server"""
|
"""A API wrapper for Satisfactory dedicated server"""
|
||||||
__AUTHOR__ = 'anima'
|
__AUTHOR__ = 'anima'
|
||||||
__VERSION__ = '0.4.3'
|
__VERSION__ = '0.5.2'
|
||||||
|
|
||||||
def __init__(self, host: str = None, port: int = 7777, token: str = None, conffile: str = 'conf.yml', logfile: str = 'SatiAPI.log', loglevel: int = 20) -> None:
|
def __init__(self, host: str = None, port: int = 7777, token: str = None, conffile: str = 'conf.yml', logfile: str = 'SatiAPI.log', loglevel: int = 20) -> None:
|
||||||
"""create a wrapper for satisfactory dedicated server
|
"""create a wrapper for satisfactory dedicated server
|
||||||
@@ -164,11 +164,9 @@ class SatiAPI:
|
|||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
if auth:
|
if auth:
|
||||||
if self.token is None:
|
if self.token is None:
|
||||||
print(self.token)
|
|
||||||
self.get_token()
|
self.get_token()
|
||||||
|
|
||||||
if self.token is None:
|
if self.token is None:
|
||||||
print(self.token)
|
|
||||||
headers['Authorization'] = f'Bearer {self.token}'
|
headers['Authorization'] = f'Bearer {self.token}'
|
||||||
else:
|
else:
|
||||||
self._log.error('no data to authencitate')
|
self._log.error('no data to authencitate')
|
||||||
@@ -180,7 +178,6 @@ class SatiAPI:
|
|||||||
if 'data' in json_response:
|
if 'data' in json_response:
|
||||||
return json_response
|
return json_response
|
||||||
else:
|
else:
|
||||||
#or if 403
|
|
||||||
# if json_response['errorMessage'] == '':
|
# if json_response['errorMessage'] == '':
|
||||||
# self._log.debug(f'token expired')
|
# self._log.debug(f'token expired')
|
||||||
# self.get_token()
|
# self.get_token()
|
||||||
@@ -193,6 +190,23 @@ class SatiAPI:
|
|||||||
self._log.debug(f'{response.request.body=}')
|
self._log.debug(f'{response.request.body=}')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _passwordless_login(self, privilegeLevel: str = 'InitialAdmin') -> bool:
|
||||||
|
"""Attempts to perform a passwordless login to the Dedicated Server as a player. Passwordless login is possible if the Dedicated Server is not claimed, or if Client Protection Password is not set for the Dedicated Server. This function requires no Authentication.
|
||||||
|
|
||||||
|
:param privilegeLevel: Minimum privilege level to attempt to acquire by logging in. See Privilege Level enum for possible values
|
||||||
|
:type privilegeLevel: string
|
||||||
|
:return: true if successfull
|
||||||
|
:rtype: bool
|
||||||
|
"""
|
||||||
|
data = dict()
|
||||||
|
data['MinimumPrivilegeLevel'] = privilegeLevel
|
||||||
|
|
||||||
|
response = self.__query('PasswordlessLogin', data)
|
||||||
|
if response:
|
||||||
|
self.token = response['data']['authenticationToken']
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return response
|
||||||
|
|
||||||
def get_token(self, password: str = None, privilegeLevel: str = 'Administrator') -> bool:
|
def get_token(self, password: str = None, privilegeLevel: str = 'Administrator') -> bool:
|
||||||
"""get token from satisfacory dedicated server, password is needed!
|
"""get token from satisfacory dedicated server, password is needed!
|
||||||
@@ -231,7 +245,7 @@ class SatiAPI:
|
|||||||
|
|
||||||
response = self.__query('PasswordLogin', data)
|
response = self.__query('PasswordLogin', data)
|
||||||
if response:
|
if response:
|
||||||
self.token = response['authenticationToken']
|
self.token = response['data']['authenticationToken']
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return response
|
return response
|
||||||
@@ -273,8 +287,6 @@ class SatiAPI:
|
|||||||
"""
|
"""
|
||||||
return self.__query('GetAdvancedGameSettings')
|
return self.__query('GetAdvancedGameSettings')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## todo
|
## todo
|
||||||
@@ -303,6 +315,7 @@ if __name__ == "__main__":
|
|||||||
# print(sati.get_token())
|
# print(sati.get_token())
|
||||||
# print(sati.token)
|
# print(sati.token)
|
||||||
# print(sati.get_status())
|
# print(sati.get_status())
|
||||||
print(sati.claim_server('SDGame01', 'Admin123!'))
|
print(sati._passwordless_login())
|
||||||
|
# print(sati.claim_server('SDGame01', 'Admin123!'))
|
||||||
|
|
||||||
# print(sati.get_status())
|
# print(sati.get_status())
|
||||||
Reference in New Issue
Block a user