diff --git a/league_client/rso/auth.py b/league_client/rso/auth.py index 68888bc..899b0db 100644 --- a/league_client/rso/auth.py +++ b/league_client/rso/auth.py @@ -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 @@ -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) diff --git a/league_client/rso/password.py b/league_client/rso/password.py index 2a6d1f7..0f118e1 100644 --- a/league_client/rso/password.py +++ b/league_client/rso/password.py @@ -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 = "" match = re.search(pattern, text) @@ -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, diff --git a/league_client/shortcuts/rso.py b/league_client/shortcuts/rso.py index 03bb4f5..7afc42b 100644 --- a/league_client/shortcuts/rso.py +++ b/league_client/shortcuts/rso.py @@ -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 @@ -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 @@ -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 + )