Jump to content
McKay Development

Recommended Posts

Posted

Previously I used it like this:

const community = new SteamCommunity({
request: Request.defaults({
forever: true,
proxy: proxy,
}),
});


now with this approach I get an error: Error: SteamCommunity.login() is incompatible with node-steamcommunity v3's usage of 'request'. If you need to specify a custom 'request' instance (e.g. when using a proxy), use https://www.npmjs.com/package/steam-session directly to log onto Steam.

please tell me what should I do now?

Posted
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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...