Skip to content

Commit

Permalink
remove sus proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio committed May 27, 2023
1 parent ae09415 commit b56460c
Showing 1 changed file with 2 additions and 33 deletions.
35 changes: 2 additions & 33 deletions src/OpenAIAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ def __init__(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/109.0.0.0 Safari/537.36"
)
self.api_prefix = getenv("CHATGPT_API_PREFIX", "https://ai.fakeopen.com")

@staticmethod
def __check_email(email: str):
regex = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b"
return re.fullmatch(regex, email)

def auth(self, login_local=True) -> str:
def auth(self) -> str:
if (
self.use_cache
and self.access_token
Expand All @@ -61,7 +60,7 @@ def auth(self, login_local=True) -> str:
if not self.__check_email(self.email) or not self.password:
raise Exception("invalid email or password.")

return self.__part_two() if login_local else self.get_access_token_proxy()
return self.__part_two()

def __part_two(self) -> str:
code_challenge = "w6n3Ix420Xhhu-Q5-mOOEyuPZmAsJHUbBpO8Ub7xBCY"
Expand Down Expand Up @@ -247,33 +246,3 @@ def get_access_token(self, code_verifier: str, callback_url: str) -> str:
return self.access_token
else:
raise Exception(resp.text)

def get_access_token_proxy(self) -> str:
url = "{}/api/auth/login".format(self.api_prefix)
headers = {
"User-Agent": self.user_agent,
}
data = {
"username": self.email,
"password": self.password,
}
resp = self.session.post(
url=url,
headers=headers,
data=data,
allow_redirects=False,
**self.req_kwargs
)

if resp.status_code == 200:
json = resp.json()
if "accessToken" not in json:
raise Exception("Get access token failed.")

self.access_token = json["accessToken"]
self.expires = dt.strptime(
json["expires"], "%Y-%m-%dT%H:%M:%S.%fZ"
) - datetime.timedelta(minutes=5)
return self.access_token
else:
raise Exception("Error get access token.")

0 comments on commit b56460c

Please sign in to comment.