DoctorMcKay / node-steam-session

Node.js module for authenticating with the Steam auth server. Allows for generating refresh tokens and web auth cookies for use with steam-user and other packages.
https://www.npmjs.com/package/steam-session
MIT License
117 stars 22 forks source link

Error: Malformed login response #15

Closed lovesmurf closed 1 year ago

lovesmurf commented 1 year ago

Woke up today and found that I was getting a lot of error messages when receiving cookies, then the process dies off. Please tell me, should I always catch catch on getWebCookies function? And what is causing this error?

3|trades   | Error: Malformed login response
3|trades   |     at LoginSession.getWebCookies (/app/node_modules/steam-session/dist/LoginSession.js:397:19)
3|trades   |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
3|trades   |     at async checkExpiredTokens (/app/core/tradeHandlers/bot/login.js:68:25)
3|trades   |     at async handle (/app/core/tradeHandlers/bot/login.js:230:11)
3|trades   | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
3|trades   | Error: Malformed login response
3|trades   |     at LoginSession.getWebCookies (/app/node_modules/steam-session/dist/LoginSession.js:397:19)
3|trades   |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
3|trades   |     at async checkExpiredTokens (/app/core/tradeHandlers/bot/login.js:68:25)
3|trades   |     at async handle (/app/core/tradeHandlers/bot/login.js:230:11)
3|trades   | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
3|trades   | Error: Malformed login response
3|trades   |     at LoginSession.getWebCookies (/app/node_modules/steam-session/dist/LoginSession.js:397:19)
3|trades   |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
3|trades   |     at async checkExpiredTokens (/app/core/tradeHandlers/bot/login.js:68:25)
3|trades   |     at async handle (/app/core/tradeHandlers/bot/login.js:230:11)
3|trades   | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
3|trades   | Error: Malformed login response
3|trades   |     at LoginSession.getWebCookies (/app/node_modules/steam-session/dist/LoginSession.js:397:19)
3|trades   |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
3|trades   |     at async checkExpiredTokens (/app/core/tradeHandlers/bot/login.js:68:25)
3|trades   |     at async handle (/app/core/tradeHandlers/bot/login.js:230:11)
3|trades   | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
3|trades   | Error: Malformed login response
3|trades   |     at LoginSession.getWebCookies (/app/node_modules/steam-session/dist/LoginSession.js:397:19)
3|trades   |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
3|trades   |     at async checkExpiredTokens (/app/core/tradeHandlers/bot/login.js:68:25)
3|trades   |     at async handle (/app/core/tradeHandlers/bot/login.js:230:11)
3|trades   | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
3|trades   | Error: Malformed login response
3|trades   |     at LoginSession.getWebCookies (/app/node_modules/steam-session/dist/LoginSession.js:397:19)
3|trades   |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
3|trades   |     at async checkExpiredTokens (/app/core/tradeHandlers/bot/login.js:68:25)
3|trades   |     at async handle (/app/core/tradeHandlers/bot/login.js:230:11)
DoctorMcKay commented 1 year ago

Works fine for me. Was this happening yesterday during Steam's weekly downtime?

You should always catch errors from anything that could throw one, especially network requests. Errors are always possible when networks are involved.

lovesmurf commented 1 year ago

Works fine for me. Was this happening yesterday during Steam's weekly downtime?

You should always catch errors from anything that could throw one, especially network requests. Errors are always possible when networks are involved.

I noticed that this happens when Steam Logon services are in surge status. But the problem is that the exception is still issued even if I break its processing. Then the process dies accordingly

try {
const webCookies = await session.getWebCookies()
} catch(e) {
return false;
}
lovesmurf commented 1 year ago

Works fine for me. Was this happening yesterday during Steam's weekly downtime?

You should always catch errors from anything that could throw one, especially network requests. Errors are always possible when networks are involved.

It feels like getWebCookies goes into a state of infinite waiting

DoctorMcKay commented 1 year ago

I can't reproduce this.

try {
    session.refreshToken = 'eyAid...';
    console.log(await session.getWebCookies());
} catch (ex) {
    console.log('getWebCookies() error');
    console.log(ex);
}

Output:

getWebCookies() error
Error: Malformed login response
    at LoginSession.getWebCookies (path\to\steam-session\src\LoginSession.ts:528:18)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async main (path\to\steam-session\dev\test2.ts:23:15)
lovesmurf commented 1 year ago

That solved my problem.

timeout = setTimeout(() => { return reject(); }, 20000);

let startResult = await session.startWithCredentials({
          accountName: bot.login,
          password: bot.password,
          steamGuardCode: authCode,
        });
        logger.info("startWithCredentials success");

        let timeout = null;

        await new Promise((resolve, reject) => {
          timeout = setTimeout(() => {
            return reject();
          }, 20000);

          session.on("authenticated", async () => {
            console.log("\nAuthenticated successfully! Printing your tokens now...");
            console.log(`SteamID: ${session.steamID}`);
            console.log(`Account name: ${session.accountName}`);
            console.log(`Access token: ${session.accessToken}`);
            console.log(`Refresh token: ${session.refreshToken}`);

            logger.info("Take webcookies authenticated");
            const webCookies = await session.getWebCookies();
            logger.info("Taken webcookies success authenticated");
            console.log("Web session cookies:");
            console.log(webCookies);

            community.setCookies(webCookies);

            const decodedAccessToken = jwt.decode(session.accessToken);
            const decodedRefreshToken = jwt.decode(session.refreshToken);
            const accessTokenExpiry = new Date(decodedAccessToken.exp * 1000);
            const refreshTokenExpiry = new Date(decodedRefreshToken.exp * 1000);

            clearTimeout(timeout);
            return resolve();
          });

          session.on("timeout", () => {
            logger.info("[fuck]: timeout");

            clearTimeout(timeout);
            return reject();
          });

          session.on("error", err => {
            console.log(`ERROR: This login attempt has failed! ${err.message}`);

            clearTimeout(timeout);
            return reject();
          });
        });
DoctorMcKay commented 1 year ago

Now that you've posted your code, I can tell you what's wrong with it.

Throwing an error in an event handler (or rejecting a promise inside an async event handler) does nothing. The error does not get bubbled or caught. You'd need to do this:

          session.on("authenticated", async () => {
            console.log("\nAuthenticated successfully! Printing your tokens now...");
            console.log(`SteamID: ${session.steamID}`);
            console.log(`Account name: ${session.accountName}`);
            console.log(`Access token: ${session.accessToken}`);
            console.log(`Refresh token: ${session.refreshToken}`);

            try {
              logger.info("Take webcookies authenticated");
              const webCookies = await session.getWebCookies();
              logger.info("Taken webcookies success authenticated");
              console.log("Web session cookies:");
              console.log(webCookies);

              community.setCookies(webCookies);
            } catch (ex) {
              reject(ex);
            }

            const decodedAccessToken = jwt.decode(session.accessToken);
            const decodedRefreshToken = jwt.decode(session.refreshToken);
            const accessTokenExpiry = new Date(decodedAccessToken.exp * 1000);
            const refreshTokenExpiry = new Date(decodedRefreshToken.exp * 1000);

            clearTimeout(timeout);
            return resolve();
          });