Skip to content

Commit 8135935

Browse files
authored
Merge pull request #56 from JacobLinCool/fix-cn-csrf-token
fix(cn): get csrf token from graphql endpoint
2 parents ed2cec1 + ae5906e commit 8135935

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/credential-cn.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ import type { ICredential } from "./types";
44
import { parse_cookie } from "./utils";
55

66
async function get_csrf() {
7-
const cookies_raw = (await fetch(BASE_URL_CN, {
7+
const res = await fetch(`${BASE_URL_CN}/graphql/`, {
8+
method: "POST",
89
headers: {
10+
"content-type": "application/json",
911
"user-agent": USER_AGENT,
1012
},
11-
}).then((res) => res.headers.get("set-cookie"))) as string;
13+
body: JSON.stringify({
14+
operationName: "nojGlobalData",
15+
variables: {},
16+
query: "query nojGlobalData {\n siteRegion\n chinaHost\n websocketUrl\n}\n",
17+
}),
18+
});
19+
const cookies_raw = res.headers.get("set-cookie") as string;
1220

1321
const csrf_token = parse_cookie(cookies_raw).csrftoken;
1422
return csrf_token;

0 commit comments

Comments
 (0)