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
112 stars 20 forks source link

Session is not persistent between restarts longer than ~2hrs #40

Open osztenkurden opened 6 months ago

osztenkurden commented 6 months ago

Describe the bug

Even with using Steam Guard Machine Token, log in fails and requires code from email

Versions

Node 20.9 steam-session ^1.7.2 I've recently updated from 0.0.4-alpha, which worked fine for the time being

Screenshots and Error Logs

const machineTokenPath = path.join(__dirname, './machinetoken');

const getMachineToken = () => {
    try {
        const content = fs.readFileSync(machineTokenPath, 'utf-8');
        return content;
    } catch {
        return null;
    }
}

const machineToken = getMachineToken();

if(!machineToken) console.log("No machine token");

export const session = new LoginSession(EAuthTokenPlatformType.SteamClient);

session.loginTimeout = 120_000;

session.on("steamGuardMachineToken", () => {
    if (session.steamGuardMachineToken) fs.writeFileSync(machineTokenPath, session.steamGuardMachineToken, 'utf-8');
});

session.startWithCredentials({
    accountName: env.ACCOUNT_NAME,
    password: env.PASSWORD,
    steamGuardMachineToken: machineToken || undefined
}).then(result => {
    if (result.actionRequired) {
        logger.warn("AUTH FAILED ACTION REQUIRED");
    }
}).catch((e) => {
    logger.error("Login failed", e);
});

I have another handler, where I can input 2FA code through http request. When I input that, user logs in and machine token saves on disk. If I restart it imidiately, it logs in, but when I restart it around 2hrs later, it requires 2FA code again. When using 0.0.4 up to today, it worked and logged all the time, even after restarting after days of uptime.

osztenkurden commented 6 months ago

It seems that this happens, if for some reason there is disconnection, and auto retry kicks in. Around 5am my app got disconnected, successfully relogged, and when I restart now, it prompted me for 2FA again: image

This is code for authentication and log in:

session.on('authenticated', async () => {
    logger.info('Authenticated successfully!');
    logger.info(`SteamID: ${session.steamID}`);

    const client = new SteamUser();
    sessionContext.client = client;

    client.on("appLaunched", appid => {
        if (appid !== 730) {
            return;
        }
        logger.info("CS2 Started");

    });
    client.on('disconnected', async () => {
        logger.info("Disconnected, retrying log in");
    })
    client.on('loggedOn', async () => {
        logger.info("User logged on");
        client.setPersona(SteamUser.EPersonaState.Online);
    });
    if (session.refreshToken) client.logOn({ refreshToken: session.refreshToken } as any);
});
osztenkurden commented 6 months ago

Right now the 2FA got triggered after 10minutes - at 11:04 I restarted server, it authed normally, and after 10 minutes I restarted it again, and even though it passed the Steam Guard Machine token, 2FA got triggered anyway

osztenkurden commented 5 months ago

Got around that by disabling 2FA, and then enabling it programatically through steam-user, and having backend auto-generating code on its own through steam-totp, so maybe I should close it?

DoctorMcKay commented 1 week ago

Is there any reason why you're not just letting steam-user handle machine tokens by itself?