node-steam-session
node-steam-session copied to clipboard
Session is not persistent between restarts longer than ~2hrs
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.
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:
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);
});
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
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?
Is there any reason why you're not just letting steam-user handle machine tokens by itself?