steam-user

repository·master·Indexed 22 days ago

https://github.com/doctormckay/node-steam-user

A Node.js module that allows interaction with the Steam network by communicating via the Steam client protocol. It supports Individual and AnonUser Steam account types, providing functionality for authentication (including refresh tokens and machine auth tokens), account metadata retrieval, Steam Guard management, and messaging via the SteamChatRoomClient.

Tokens
15.4K
Snippets
34
Records
77
Agent score
76%

What's inside steam-user

  1. Use SteamChatRoomClient instead of deprecated chat methods

    master
    Most legacy chat methods on the SteamUser instance are deprecated. Instead of using methods like chatMessage, joinChat, or createChatRoom, you should use the SteamChatRoomClient available via the chat property of your SteamUser instance. This new client is compatible with Steam's modern chat system.
  2. Use SteamChatRoomClient instead of deprecated chat events

    master

    Most legacy chat-related events in SteamUser are deprecated. Instead of listening to events like friendMessage, chatMessage, or chatUserJoined directly on the SteamUser instance, you should use the SteamChatRoomClient available via the chat property of your SteamUser instance.

    Deprecated events include:

    • friendOrChatMessage
    • friendMessage
    • friendTyping
    • friendLeftConversation
    • friendMessageEcho
    • friendTypingEcho
    • chatMessage (and ID variants like chatMessage#roomID)
    • chatHistory
    • chatInvite (and ID variants like chatInvite#inviterID#chatID)
    • chatCreated
    • chatEnter
    • chatLeft
    • chatUserJoined
    • chatUserLeft
    • chatUserDisconnected
    • chatUserKicked
    • chatUserBanned
    • chatUserSpeaking
    • chatUserDoneSpeaking
    • chatSetPublic
  3. Use SteamChatRoomClient instead of legacy chat events

    master

    The legacy chat room events (such as chatSetPrivate, chatSetOfficersOnly, and others related to chat room locking/unlocking) are deprecated.

    Instead of listening to these events directly on the SteamUser instance, you should use the SteamChatRoomClient which is accessible via the chat property of your SteamUser instance. For detailed usage, refer to the SteamChatRoomClient documentation.

  4. How ID events work in SteamUser

    master

    Events marked as ID events allow you to listen to specific users by appending their 64-bit SteamID to the event name using a # separator.

    When an ID event fires, two listeners are triggered:

    1. A general listener for the base eventName (which receives the SteamID object as the first parameter).
    2. A specific listener for eventName#<steamID64> (which also receives the SteamID object as the first parameter).

    This is useful for filtering events for a specific friend or contact without manually checking the ID inside every callback.

    // This will fire when we receive a chat message from ANY friend
    user.on('friendMessage', function(steamID, message) {
    	console.log("Friend message from " + steamID.getSteam3RenderedID() + ": " + message);
    });
    
    // This will fire when we receive a chat message from [U:1:46143802] / 76561198006409530 ONLY
    user.on('friendMessage#76561198006409530', function(steamID, message) {
    	console.log("Friend message from " + steamID.getSteam3RenderedID() + ": " + message);
    });
  5. Use Callbacks or Promises with SteamUser methods

    master

    Most SteamUser methods support both callbacks and Promises.

    • Promises: All methods that return data return a Promise that resolves to a single object containing the method's data properties.
    • Callbacks: Legacy callbacks return data across multiple arguments. Newer callbacks return a single response object that is identical to the Promise output.

    Important Note on Error Handling:

    • You are never required to use callbacks over Promises.
    • If a callback is listed as optional, an unhandled promise rejection will not raise a warning/error.
    • If a callback is listed as required and you provide neither a callback nor handle the promise rejection, a promise rejection will raise a warning and may eventually cause a crash.
  6. Check Steam Guard trading requirements

    master

    To determine if an account is eligible for trading, you must verify several Steam Guard conditions. An account is considered to meet trading requirements if:

    1. isSteamGuardEnabled is true.
    2. timestampSteamGuardEnabled is at least 15 days in the past.
    3. Either timestampMachineSteamGuardEnabled OR timestampTwoFactorEnabled is at least 7 days in the past.

    Use the account details request to retrieve these timestamps.

  7. Access Steam enums via SteamUser

    master

    Steam enums are available directly on the SteamUser module. For example, you can access EResult via SteamUser.EResult.

    For convenience, you can perform reverse lookups. If you have an enum value (e.g., 88), you can retrieve its string name (e.g., TwoFactorCodeMismatch) by accessing the enum as an object: SteamUser.EResult[88].

    // Example of reverse lookup
    const resultName = SteamUser.EResult[88]; // 'TwoFactorCodeMismatch'
  8. How Refresh Tokens work

    master

    Refresh tokens are the recommended way to maintain long-term sessions. They are JWTs valid for approximately 200 days.

    When you log on using an accountName and password, steam-user will internally fetch a refresh token, emit the refreshToken event, and then use that token for subsequent logins. You can decode the JWT to check the exp property to see when the token expires.

  9. How Machine Auth Tokens work

    master

    When using email Steam Guard, machine auth tokens allow a device to be remembered, bypassing the need for a code every time you log in.

    By default, steam-user automatically saves these tokens in your dataDirectory. You can also manage them manually by listening for the machineAuthToken event and providing the token via the machineAuthToken property in logOn().

  10. Handle Steam Guard authentication

    master

    The steamGuard event is emitted when Steam requests an authentication code (via email or app).

    Important for 2FA users: If you are using Two-Factor Authentication (TOTP), you must check the lastCodeWrong argument. If lastCodeWrong is true, the previous code provided was incorrect or already used. You must wait 30 seconds before providing a new code to allow the TOTP algorithm to generate a new one. Failing to wait can result in a login loop and a temporary IP ban.

    If no listener is bound to this event, steam-user will attempt to prompt the user for a code via stdin.

    user.on('steamGuard', function(domain, callback) {
    	console.log("Steam Guard code needed from email ending in " + domain);
    	var code = getCodeSomehow();
    	callback(code);
    });
  11. Enable Two-Factor Authentication (TOTP)

    master

    You can start the process of enabling TOTP (Two-Factor Authentication) using enableTwoFactor() and finalizeTwoFactor().

    1. enableTwoFactor(callback): Starts the process. You will receive an activation code via SMS or email. The callback returns a response object containing shared_secret, identity_secret, and revocation_code. Save this response securely.
    2. finalizeTwoFactor(secret, activationCode, callback): Finishes the process. secret is the shared_secret from the previous step (as a Buffer), and activationCode is the code you received.

    Note: Once enabled, you will need a code for every login unless you use a refresh token.

    steamUser.enableTwoFactor((err, response) => {
        if (err) return console.error(err);
        
        // response.shared_secret is needed for finalizeTwoFactor
        const secret = response.shared_secret;
        const activationCode = '123456'; // From SMS/Email
    
        steamUser.finalizeTwoFactor(secret, activationCode, (err) => {
            if (err) console.error(err);
            else console.log('Two-factor enabled!');
        });
    });