Trying to add Google authorization
This commit is contained in:
parent
0aace40e2c
commit
ca9cda3b51
6 changed files with 86 additions and 66 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,7 @@
|
|||
# Python
|
||||
__pycache__
|
||||
dist/*
|
||||
*.egg-info/*
|
||||
|
||||
# Vim
|
||||
*.swp
|
||||
|
|
|
@ -1,43 +1,40 @@
|
|||
import hashlib
|
||||
import lxml.html
|
||||
from typing import Optional, List
|
||||
from typing import Optional, Union, List
|
||||
|
||||
from . import atserver
|
||||
from . import atconnect
|
||||
from . import aterrors
|
||||
from . import client_secrets
|
||||
|
||||
class Client:
|
||||
|
||||
def __init__(
|
||||
self, username:str,
|
||||
password:Optional[str]=None,
|
||||
md5:Optional[str]=None) -> None:
|
||||
def __init__(self, atconn:atconnect.AternosConnect) -> None:
|
||||
|
||||
if (password == None) and (md5 == None):
|
||||
raise AttributeError('Password was not specified')
|
||||
self.atconn = atconn
|
||||
|
||||
if (password != None):
|
||||
self.__init__(
|
||||
username,
|
||||
md5=hashlib.md5(password.encode('utf-8'))\
|
||||
.hexdigest().lower()
|
||||
)
|
||||
return
|
||||
# if google:
|
||||
# flow = Flow.from_client_config\
|
||||
# (
|
||||
# json.loads(
|
||||
# base64.standard_base64decode(client_secrets.CSJSON)
|
||||
# ),
|
||||
# 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()
|
||||
self.sec = self.atconn.generate_sec()
|
||||
|
||||
self.credentials = {
|
||||
'user': username,
|
||||
'password': md5
|
||||
}
|
||||
atconn = atconnect.AternosConnect()
|
||||
token = atconn.parse_token()
|
||||
sec = atconn.generate_sec()
|
||||
|
||||
loginreq = self.atconn.request_cloudflare(
|
||||
f'https://aternos.org/panel/ajax/account/login.php?' + \
|
||||
f'SEC={self.sec}&TOKEN={self.token}',
|
||||
atconnect.REQPOST, data=self.credentials
|
||||
f'https://aternos.org/panel/ajax/account/login.php',
|
||||
atconnect.REQPOST, data=self.credentials,
|
||||
sendtoken=True
|
||||
)
|
||||
|
||||
if loginreq.cookies.get('ATERNOS_SESSION', None) == None:
|
||||
|
@ -45,6 +42,20 @@ class Client:
|
|||
'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
|
||||
def servers(self) -> List[atserver.AternosServer]:
|
||||
serverspage = self.atconn.request_cloudflare(
|
||||
|
|
|
@ -89,10 +89,7 @@ class AternosConnect:
|
|||
cftitle = '<title>Please Wait... | Cloudflare</title>'
|
||||
|
||||
if sendtoken:
|
||||
if params == None:
|
||||
params = {}
|
||||
params['SEC'] = self.sec
|
||||
params['TOKEN'] = self.token
|
||||
url += f'?TOKEN={self.token}&SEC={self.sec}'
|
||||
|
||||
if headers == None:
|
||||
headers = {}
|
||||
|
@ -150,4 +147,12 @@ class AternosConnect:
|
|||
)
|
||||
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
|
||||
|
|
|
@ -1,37 +1,37 @@
|
|||
import re
|
||||
import js2py
|
||||
import base64
|
||||
|
||||
brkregex = re.compile(r'\((?!\)|[\'\"])(.+?)(?<!\(|[\'\"])\)')
|
||||
|
||||
def parse_brackets(f):
|
||||
return brkregex.search(f)[1]
|
||||
|
||||
def to_ecma5_function(f):
|
||||
fnstart = f.find('{')+1
|
||||
fnend = f.rfind('}')
|
||||
f = arrow_conv(f[fnstart:fnend])
|
||||
return f
|
||||
|
||||
def atob(s):
|
||||
return base64.standard_b64decode(str(s)).decode('utf-8')
|
||||
|
||||
def arrow_conv(f):
|
||||
if '=>' in f:
|
||||
inner = parse_brackets(f)
|
||||
while brkregex.match(inner) != None:
|
||||
inner = parse_brackets(inner)
|
||||
|
||||
func = re.sub(
|
||||
r'(\w+)\s*=>\s*(.+)',
|
||||
r'function(\1){return \2}', inner
|
||||
)
|
||||
start = f.find(inner)
|
||||
end = start + len(inner)
|
||||
f = f[:start] + func + f[end:]
|
||||
return f
|
||||
|
||||
def exec(f):
|
||||
ctx = js2py.EvalJs({'atob': atob})
|
||||
ctx.execute(to_ecma5_function(f))
|
||||
return ctx
|
||||
import re
|
||||
import js2py
|
||||
import base64
|
||||
|
||||
brkregex = re.compile(r'\((?!\)|[\'\"])(.+?)(?<!\(|[\'\"])\)')
|
||||
|
||||
def parse_brackets(f):
|
||||
return brkregex.search(f)[1]
|
||||
|
||||
def to_ecma5_function(f):
|
||||
fnstart = f.find('{')+1
|
||||
fnend = f.rfind('}')
|
||||
f = arrow_conv(f[fnstart:fnend])
|
||||
return f
|
||||
|
||||
def atob(s):
|
||||
return base64.standard_b64decode(str(s)).decode('utf-8')
|
||||
|
||||
def arrow_conv(f):
|
||||
if '=>' in f:
|
||||
inner = parse_brackets(f)
|
||||
while brkregex.match(inner) != None:
|
||||
inner = parse_brackets(inner)
|
||||
|
||||
func = re.sub(
|
||||
r'(\w+)\s*=>\s*(.+)',
|
||||
r'function(\1){return \2}', inner
|
||||
)
|
||||
start = f.find(inner)
|
||||
end = start + len(inner)
|
||||
f = f[:start] + func + f[end:]
|
||||
return f
|
||||
|
||||
def exec(f):
|
||||
ctx = js2py.EvalJs({'atob': atob})
|
||||
ctx.execute(to_ecma5_function(f))
|
||||
return ctx
|
||||
|
|
|
@ -129,6 +129,7 @@ class AternosServer:
|
|||
headers:Optional[dict]=None,
|
||||
sendtoken:bool=False) -> Response:
|
||||
|
||||
print(sendtoken)
|
||||
return self.atconn.request_cloudflare(
|
||||
url=url, method=method,
|
||||
params=params, data=data,
|
||||
|
|
1
python_aternos/client_secrets.py
Normal file
1
python_aternos/client_secrets.py
Normal file
|
@ -0,0 +1 @@
|
|||
CSJSON = 'eyJpbnN0YWxsZWQiOnsiY2xpZW50X2lkIjoiNjU4MTQyNjkxNjQxLXFnZ21sdGNmdXY0a2I1a2NwczdoZjBiaGlvN2Q0dnUzLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwicHJvamVjdF9pZCI6InB5dGhvbi1hdGVybm9zIiwiYXV0aF91cmkiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvYXV0aCIsInRva2VuX3VyaSI6Imh0dHBzOi8vb2F1dGgyLmdvb2dsZWFwaXMuY29tL3Rva2VuIiwiYXV0aF9wcm92aWRlcl94NTA5X2NlcnRfdXJsIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vb2F1dGgyL3YxL2NlcnRzIiwiY2xpZW50X3NlY3JldCI6IkdPQ1NQWC1XUUJsMjIzOTZxcHVLMDJIVXVpWUhhUXNmbC03IiwicmVkaXJlY3RfdXJpcyI6WyJ1cm46aWV0Zjp3ZzpvYXV0aDoyLjA6b29iIiwiaHR0cDovL2xvY2FsaG9zdCJdfX0='
|
Reference in a new issue