Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cn_fetch_cookie_token_with_stoken_v2 function #213

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions genshin/client/manager/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- fetch_cookie_with_stoken_v2
- stoken (v2) + mid -> ltoken_v2 (token_type=2)
- stoken (v2) + mid -> cookie_token_v2 (token_type=4)
- cn_fetch_cookie_token_with_stoken_v2
- stoken (v2) + mid -> cookie_token
- fetch_cookie_token_with_game_token
- game_token -> cookie_token
- fetch_stoken_with_game_token
Expand All @@ -37,6 +39,7 @@
from genshin.utility import ds as ds_utility

__all__ = [
"cn_fetch_cookie_token_with_stoken_v2",
"complete_cookies",
"fetch_cookie_token_info",
"fetch_cookie_token_with_game_token",
Expand Down Expand Up @@ -116,6 +119,27 @@ async def fetch_cookie_with_stoken_v2(
return cookies


async def cn_fetch_cookie_token_with_stoken_v2(
cookies: managers.CookieOrHeader,
) -> typing.Mapping[typing.Literal["uid", "cookie_token"], str]:
"""Fetch cookie_token with an stoken (v2) and mid."""
cookies = managers.parse_cookie(cookies)
url = routes.CN_GET_COOKIE_TOKEN_BY_STOKEN_URL.get_url()

headers = {
"ds": ds_utility.generate_dynamic_secret(constants.DS_SALT["app_login"]),
"x-rpc-app_id": "bll8iq97cem8",
}
async with aiohttp.ClientSession() as session:
r = await session.request("GET", url, headers=headers, cookies=cookies)
data = await r.json()

if data["retcode"] != 0:
errors.raise_for_retcode(data)

return data["data"]


async def fetch_cookie_token_info(
cookies: managers.CookieOrHeader,
*,
Expand Down
3 changes: 3 additions & 0 deletions genshin/client/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ def get_url(self, region: types.Region, game: types.Game) -> yarl.URL:
COOKIE_V2_REFRESH_URL = Route("https://sg-public-api.hoyoverse.com/account/ma-passport/token/getBySToken")
GET_COOKIE_TOKEN_BY_GAME_TOKEN_URL = Route("https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken")
GET_STOKEN_BY_GAME_TOKEN_URL = Route("https://passport-api.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken")
CN_GET_COOKIE_TOKEN_BY_STOKEN_URL = Route(
"https://passport-api.mihoyo.com/account/auth/api/getCookieAccountInfoBySToken"
)

WEB_LOGIN_URL = Route("https://sg-public-api.hoyolab.com/account/ma-passport/api/webLoginByPassword")
APP_LOGIN_URL = Route("https://sg-public-api.hoyoverse.com/account/ma-passport/api/appLoginByPassword")
Expand Down
Loading