Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
6.2 kB
62
Indexable
Never
import contextlib
from secrets import token_urlsafe
from httpx import Client
import requests
from dataclasses import dataclass
from time import time
import jwt
import capmonster_python
import json
import uuid

def magic_decode(string: str):
    with contextlib.suppress(json.JSONDecodeError):
        return json.loads(string)
    with contextlib.suppress(jwt.exceptions.DecodeError):
        return jwt.decode(string, options={"verify_signature": False})
    raise DecodeException

@dataclass
class User:
    username: str = ''
    password: str = ''
    def __hash__(self):
        return hash(self.username)

@dataclass
class Token():
    access_token: str
    id_token: str
    expire: float
    created = time()

class Version:
    def __init__(self):
        self.versions = requests.get("https://valorant-api.com/v1/version").json()["data"]
        self.valorant = self.valorant()
        self.riot = self.riot()
        self.sdk = self.sdk()

    def riot(self):
        return self.versions["riotClientBuild"]
    def sdk(self):
        return sdk if (sdk := self.versions["riotClientVersion"].split(".")[1]) else "23.8.0.1382"
    def valorant(self):
        return self.versions["riotClientVersion"]

version = Version()

class CaptchaFlow:
    def __init__(self, session, user):
        self.ses = session
        self.user = user

    def get_captcha_token(self):
        data = {
            "clientId": "riot-client",
            "language": "ru-RU",
            "platform": "web",
            "remember": False,
            "riot_identity": {
                "language": "it_IT",
                "state": "auth",
            },
            "sdkVersion": version.sdk,
            "type": "auth",
        }
        url = "https://authenticate.riotgames.com/api/v1/login"
        response_data = self.ses.get(url).json()
        print(response_data)
        return response_data

    def get_login_token(self, code: str):
        data = {
            "riot_identity": {
                "captcha": f"hcaptcha {code}",
                "language": "ru_RU",
                "password": self.user.password,
                "remember": False,
                "username": self.user.username
            },
            "type": "auth"
        }
        url = "https://authenticate.riotgames.com/api/v1/login"
        response_data = self.ses.put(url, json=data).json()
        print(response_data)
        return response_data

    def login_cookies(self, login_token: str):
        data = {
            "authentication_type": "RiotAuth",
            "code_verifier": "",
            "login_token": login_token,
            "persist_login": False
        }
        url = "https://auth.riotgames.com/api/v1/login-token"
        self.ses.post(url, json=data)

    def solve_captcha(self, data):
        sitekey = data["captcha"]["hcaptcha"]["key"]
        rqdata = data["captcha"]["hcaptcha"]["data"]
        capmonster = capmonster_python.HCaptchaTask("key")
        print(sitekey)
        capmonster.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36")
        task_id = capmonster.create_task(website_url="https://auth.riotgames.com", website_key=sitekey, custom_data=rqdata)
        result = capmonster.join_task_result(task_id)
        return result.get("gRecaptchaResponse")

    def captcha_flow(self):
        captcha_data = self.get_captcha_token()
        captcha_token = self.solve_captcha(captcha_data)
        login_token = self.get_login_token(captcha_token)
        self.login_cookies(login_token)

class RiotAuth:
    def __init__(self, user):
        self.session = self.setup_session()
        self.setup_auth(self.session)
        CaptchaFlow(self.session, user).captcha_flow()
        self.token, self.cookies = self.get_auth_data(self.session)

    def setup_session(self):
        app = "rso-auth"
        session = Client()
        session.headers.update({
            "User-Agent": f'RiotClient/{version.riot} {app} (Windows;10;;Professional, x64)',
            "Cache-Control": "no-cache",
            "Accept": "application/json",
            "Content-Type": "application/json"
        })
        session.cookies.update({"tdid": "", "asid": "", "did": "", "clid": ""})
        return session

    def setup_auth(self, session):
        data = {
            "acr_values": "urn:riot:gold",
            "client_id": "accountodactyl-prod",
            "redirect_uri": "https://account.riotgames.com/oauth2/log-in",
            "response_type": "code",
            "scope": "openid email profile riot:/riot.atlas/accounts.edit riot:/riot.atlas/accounts/password.edit "
                     "riot:/riot.atlas/accounts/email.edit riot:/riot.atlas/accounts.auth riot://third_party.revoke "
                     "riot://third_party.query riot://forgetme/notify.write riot:/riot.authenticator/auth.code "
                     "riot:/riot.authenticator/authz.edit riot:/rso/mfa/device.write "
                     "riot:/riot.authenticator/identity.add",
            "state": str(uuid.uuid4()),
            "security_profile": "high"
        }

        url = "https://auth.riotgames.com/api/v1/authorization"
        r = session.post(url, json=data)
        print(r.json())
        return r

    def get_auth_data(self, session):
        r = self.setup_auth(session)
        cookies = dict(r.cookies)
        print(cookies)
        data = r.json()
        print(data)
        if "error" in data: raise Exception(data["error"])
        uri = "test"
        token = "2"
        return token, cookies



def get_user_info(session, token: Token) -> str:
    headers = {
        "Accept-Encoding": "gzip, deflate, br",
        "Authorization": f"Bearer {token.access_token}",
    }
    r = session.post("https://auth.riotgames.com/userinfo", headers=headers, json={})
    return magic_decode(r.text)


if __name__ == "__main__":
    user = User("Sussy710", "dhruv710")
    client = RiotAuth(user)
Leave a Comment