fix: wrong base64 encode/decode. fix #4

main
spacemeowx2 2022-10-24 15:15:46 +08:00
parent 1c202e03fa
commit 4a02f6da8c
2 changed files with 14 additions and 7 deletions

View File

@ -318,7 +318,7 @@ async function getSessionToken({
}): Promise<string | undefined> { }): Promise<string | undefined> {
const fetch = wrapFetch({ cookieJar }); const fetch = wrapFetch({ cookieJar });
const res = await fetch( const resp = await fetch(
"https://accounts.nintendo.com/connect/1.0.0/api/session_token", "https://accounts.nintendo.com/connect/1.0.0/api/session_token",
{ {
method: "POST", method: "POST",
@ -338,8 +338,15 @@ async function getSessionToken({
}), }),
}, },
); );
const resBody = await res.json(); const json = await resp.json();
return resBody["session_token"]; if (json.error) {
throw new APIError({
response: resp,
json,
message: "Error getting session token",
});
}
return json["session_token"];
} }
type IminkResponse = { type IminkResponse = {

View File

@ -6,16 +6,16 @@ const stdinLines = io.readLines(Deno.stdin);
export function urlBase64Encode(data: ArrayBuffer) { export function urlBase64Encode(data: ArrayBuffer) {
return base64.encode(data) return base64.encode(data)
.replaceAll("+", "_") .replaceAll("+", "-")
.replaceAll("/", "-") .replaceAll("/", "_")
.replaceAll("=", ""); .replaceAll("=", "");
} }
export function urlBase64Decode(data: string) { export function urlBase64Decode(data: string) {
return base64.decode( return base64.decode(
data data
.replaceAll("_", "+") .replaceAll("_", "/")
.replaceAll("-", "/"), .replaceAll("-", "+"),
); );
} }