Trying to add Google authorization

This commit is contained in:
DarkCat09 2022-01-06 19:57:26 +04:00
parent 0aace40e2c
commit ca9cda3b51
6 changed files with 86 additions and 66 deletions

2
.gitignore vendored
View file

@ -1,5 +1,7 @@
# Python # Python
__pycache__ __pycache__
dist/*
*.egg-info/*
# Vim # Vim
*.swp *.swp

View file

@ -1,43 +1,40 @@
import hashlib import hashlib
import lxml.html import lxml.html
from typing import Optional, List from typing import Optional, Union, List
from . import atserver from . import atserver
from . import atconnect from . import atconnect
from . import aterrors from . import aterrors
from . import client_secrets
class Client: class Client:
def __init__( def __init__(self, atconn:atconnect.AternosConnect) -> None:
self, username:str,
password:Optional[str]=None,
md5:Optional[str]=None) -> None:
if (password == None) and (md5 == None): self.atconn = atconn
raise AttributeError('Password was not specified')
if (password != None): # if google:
self.__init__( # flow = Flow.from_client_config\
username, # (
md5=hashlib.md5(password.encode('utf-8'))\ # json.loads(
.hexdigest().lower() # base64.standard_base64decode(client_secrets.CSJSON)
) # ),
return # scopes=['openid', 'email']
# )
# # localhost:8764
# flow.run_local_server(port=8764, open_browser=False)
self.atconn = atconnect.AternosConnect() @classmethod
def from_hashed(cls, username:str, md5:str):
self.token = self.atconn.parse_token() atconn = atconnect.AternosConnect()
self.sec = self.atconn.generate_sec() token = atconn.parse_token()
sec = atconn.generate_sec()
self.credentials = {
'user': username,
'password': md5
}
loginreq = self.atconn.request_cloudflare( loginreq = self.atconn.request_cloudflare(
f'https://aternos.org/panel/ajax/account/login.php?' + \ f'https://aternos.org/panel/ajax/account/login.php',
f'SEC={self.sec}&TOKEN={self.token}', atconnect.REQPOST, data=self.credentials,
atconnect.REQPOST, data=self.credentials sendtoken=True
) )
if loginreq.cookies.get('ATERNOS_SESSION', None) == None: if loginreq.cookies.get('ATERNOS_SESSION', None) == None:
@ -45,6 +42,20 @@ class Client:
'Check your username and password' 'Check your username and password'
) )
cls(atconn)
@classmethod
def from_credentials(cls, username:str, password:str):
cls.from_hashed(
username,
hashlib.md5(password.encode('utf-8'))\
.hexdigest().lower()
)
@classmethod
def with_google(cls):
pass
@property @property
def servers(self) -> List[atserver.AternosServer]: def servers(self) -> List[atserver.AternosServer]:
serverspage = self.atconn.request_cloudflare( serverspage = self.atconn.request_cloudflare(

View file

@ -89,10 +89,7 @@ class AternosConnect:
cftitle = '<title>Please Wait... | Cloudflare</title>' cftitle = '<title>Please Wait... | Cloudflare</title>'
if sendtoken: if sendtoken:
if params == None: url += f'?TOKEN={self.token}&SEC={self.sec}'
params = {}
params['SEC'] = self.sec
params['TOKEN'] = self.token
if headers == None: if headers == None:
headers = {} headers = {}
@ -150,4 +147,12 @@ class AternosConnect:
) )
countdown -= 1 countdown -= 1
print(sendtoken)
try:
print(self.sec, self.token)
except AttributeError:
pass
print(req.status_code)
print(req.cookies)
print(req.url, '', sep='\n---')
return req return req

View file

@ -129,6 +129,7 @@ class AternosServer:
headers:Optional[dict]=None, headers:Optional[dict]=None,
sendtoken:bool=False) -> Response: sendtoken:bool=False) -> Response:
print(sendtoken)
return self.atconn.request_cloudflare( return self.atconn.request_cloudflare(
url=url, method=method, url=url, method=method,
params=params, data=data, params=params, data=data,

View file

@ -0,0 +1 @@
CSJSON = 'eyJpbnN0YWxsZWQiOnsiY2xpZW50X2lkIjoiNjU4MTQyNjkxNjQxLXFnZ21sdGNmdXY0a2I1a2NwczdoZjBiaGlvN2Q0dnUzLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwicHJvamVjdF9pZCI6InB5dGhvbi1hdGVybm9zIiwiYXV0aF91cmkiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvYXV0aCIsInRva2VuX3VyaSI6Imh0dHBzOi8vb2F1dGgyLmdvb2dsZWFwaXMuY29tL3Rva2VuIiwiYXV0aF9wcm92aWRlcl94NTA5X2NlcnRfdXJsIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vb2F1dGgyL3YxL2NlcnRzIiwiY2xpZW50X3NlY3JldCI6IkdPQ1NQWC1XUUJsMjIzOTZxcHVLMDJIVXVpWUhhUXNmbC03IiwicmVkaXJlY3RfdXJpcyI6WyJ1cm46aWV0Zjp3ZzpvYXV0aDoyLjA6b29iIiwiaHR0cDovL2xvY2FsaG9zdCJdfX0='