Skip to content

Commit

Permalink
fix: move check change password to shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
chiraqL authored and pradishb committed Aug 8, 2024
1 parent 9ee7ba7 commit 562d4d8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
11 changes: 10 additions & 1 deletion league_client/rso/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from league_client.constants import RIOT_CLIENT_AUTH_PARAMS
from league_client.constants import SSL_CONTEXT
from league_client.exceptions import AuthFailureError
from league_client.exceptions import AuthMultifactorError
from league_client.exceptions import InvalidSessionError
from league_client.exceptions import RateLimitedError
from league_client.rso.utils import decode_token


Expand Down Expand Up @@ -202,9 +204,16 @@ def login_using_credentials(
with httpx.Client(verify=SSL_CONTEXT, proxy=proxy) as client:
res = authorize(client, username, password, params)
data = res.json()
if "response" in data:
response_type = data["type"]
if response_type == "response":
ssid = client.cookies["ssid"]
redirect_url = data["response"]["parameters"]["uri"]
data = process_redirect_url(redirect_url)
return (ssid, *data)
elif response_type == "multifactor":
raise AuthMultifactorError(res.text, res.status_code)
elif response_type == "auth" and data["error"] == "auth_failure":
raise AuthFailureError(res.text, res.status_code)
elif response_type == "auth" and data["error"] == "rate_limited":
raise RateLimitedError(res.text, res.status_code)
raise AuthFailureError(res.text, res.status_code)
25 changes: 1 addition & 24 deletions league_client/rso/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,11 @@

from league_client.constants import ACCOUNTODACTYL_PARAMS
from league_client.constants import HEADERS
from league_client.constants import RIOT_CLIENT_AUTH_PARAMS
from league_client.constants import SSL_CONTEXT
from league_client.exceptions import AuthFailureError
from league_client.exceptions import AuthMultifactorError
from league_client.exceptions import RateLimitedError
from league_client.rso.auth import authorize


def check_password(
username: str,
password: str,
proxy: Optional[ProxyTypes] = None,
) -> bool:
with httpx.Client(verify=SSL_CONTEXT, proxy=proxy) as client:
res = authorize(client, username, password, RIOT_CLIENT_AUTH_PARAMS)
data = res.json()
response_type = data["type"]
if response_type == "response":
return True
elif response_type == "multifactor":
raise AuthMultifactorError("Multifactor authentication")
elif response_type == "auth" and data["error"] == "auth_failure":
return False
elif response_type == "auth" and data["error"] == "rate_limited":
raise RateLimitedError("Rate limited")
raise AuthFailureError("Failed to check password")


def parse_csrf_token(text: str):
pattern = "<meta name=['\"]csrf-token['\"] content=['\"](.{36})['\"] />"
match = re.search(pattern, text)
Expand All @@ -42,7 +19,7 @@ def parse_csrf_token(text: str):
return match.group(1)


def change_password(
def change_password_using_credentials(
username: str,
password: str,
new_password: str,
Expand Down
28 changes: 28 additions & 0 deletions league_client/shortcuts/rso.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from httpx._types import ProxyTypes

from league_client.constants import LEAGUE_CLIENT_AUTH_PARAMS
from league_client.constants import RIOT_CLIENT_AUTH_PARAMS
from league_client.exceptions import AccountCheckError
from league_client.exceptions import AuthFailureError
from league_client.rso.auth import get_entitlements_token
from league_client.rso.auth import get_ledge_token
from league_client.rso.auth import get_login_queue_token
Expand All @@ -32,6 +34,7 @@
from league_client.rso.party import get_party_data
from league_client.rso.party import get_party_id
from league_client.rso.party import get_party_restrictions
from league_client.rso.password import change_password_using_credentials
from league_client.rso.rank import get_rank_data
from league_client.rso.rank import get_ranked_overview_token
from league_client.rso.rank import get_tier_division_wins_losses
Expand Down Expand Up @@ -371,3 +374,28 @@ def get_account_data(
account_data["available_queues"] = party_restrictions["availableQueueIds"]

return account_data


def check_password(
username: str,
password: str,
proxy: Optional[ProxyTypes] = None,
) -> bool:
try:
login_using_credentials(
username, password, RIOT_CLIENT_AUTH_PARAMS, proxy
)
return True
except AuthFailureError:
return False


def change_password(
username: str,
password: str,
new_password: str,
proxy: Optional[ProxyTypes] = None,
) -> bool:
return change_password_using_credentials(
username, password, new_password, proxy
)

0 comments on commit 562d4d8

Please sign in to comment.