const { LoginSession, EAuthTokenPlatformType } = require('steam-session');
const SteamCommunity = require('steamcommunity');
const SteamTotp = require('steam-totp');
// Variable [[PROXY]] sets the proxy
const proxyInput = [[PROXY]];
// Processing the proxy format
let proxyUrl;
if (proxyInput.includes('@')) {
// Proxy with authorization
const proxyParts = proxyInput.split('@');
const credentials = proxyParts[0].replace('http://', '');
const hostPort = proxyParts[1];
proxyUrl = `http://${credentials}@${hostPort}`;
} else if (proxyInput.includes(':')) {
// Proxy without authorization
proxyUrl = `http://${proxyInput}`;
} else {
[[ERR]] = 2;
[[ERR_DIS]] = "Invalid proxy format";
}
// Credentials
const username = [[LOGIN]];
const password = [[PASS]];
const sharedSecret = [[KEY]];
const identitySecret = [[IDENTITY_SECRET]];
// Generating TOTP code
const twoFactorCode = SteamTotp.generateAuthCode(sharedSecret);
// Creating a session with proxy
const session = new LoginSession(EAuthTokenPlatformType.WebBrowser, {
httpProxy: proxyUrl // Proxy for HTTP requests
});
console.log("trying to log in");
await new Promise((resolve) => {
session.on('authenticated', async () => {
try {
console.log("Successfully logged in");
// Checking refresh token
const refreshToken = session.refreshToken;
if (!refreshToken) {
console.log("Error: refresh token is missing");
[[ERR]] = 2;
[[ERR_DIS]] = "Refresh token is missing";
resolve();
return;
}
console.log("Refresh token received: " + refreshToken);
// Getting cookies
const webCookies = await session.getWebCookies();
console.log("Cookies: " + webCookies);
const community = new SteamCommunity();
community.setCookies(webCookies);
// Getting Web API key
await new Promise((resolve) => {
community.getWebApiKey((err, key) => {
if (err) {
console.log("Error getting Web API key: " + err.message);
[[ERR]] = 1;
[[ERR_DIS]] = err.message;
resolve();
} else {
console.log("Your Web API key: " + key);
[[APIKEY]] = key;
resolve(key);
}
});
});
} catch (err) {
console.log("Error getting cookies: " + err.message);
[[ERR]] = 2;
[[ERR_DIS]] = err.message;
}
resolve();
});
session.on('error', (err) => {
console.log("Login error: " + err.message);
[[ERR]] = 2;
[[ERR_DIS]] = err.message;
resolve();
});
session.startWithCredentials({
accountName: username,
password: password,
steamGuardCode: twoFactorCode
});
});
Is this how it will work or did I misunderstand?