Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
steam-session
Advanced tools
This module enables you to negotiate Steam tokens by authenticating with the Steam login server. This is for use with your own accounts. This is not to be used to authenticate other Steam users or to gain access to their accounts. For that use-case, please use the Steam OpenID service and the many available WebAPIs.
Node.js v12.22.0 or later is required to use this module.
Logging into Steam is a two-step process.
startWithCredentials
to start a login session using your account credentialsSee the examples directory on GitHub for example code.
When using CommonJS (require()
), steam-session exports an object. When using ES6 modules (import
), steam-session does
not offer a default export and you will need to import specific things.
The majority of steam-session consumers will only care about the LoginSession
class and enums.
const {EAuthSessionGuardType} = require('steam-session');
import {EAuthSessionGuardType} from 'steam-session';
Contains the possible auth session guards.
const {EAuthTokenPlatformType} = require('steam-session');
import {EAuthTokenPlatformType} from 'steam-session';
Contains the different platform types that can be authenticated for. You should specify the correct platform type when
you instantiate a LoginSession
object.
const {EResult} = require('steam-session');
import {EResult} from 'steam-session';
Contains possible result codes. This is a very large enum that used throughout Steam, so most values in this enum will not be relevant when authenticating.
const {ESessionPersistence} = require('steam-session');
import {ESessionPersistence} from 'steam-session';
Contains possible persistence levels for auth sessions.
It's possible to define a custom transport to be used when interacting with the Steam login server. By default, the
standard WebApiTransport
will be used to interact with the Steam login server using api.steampowered.com. It is very
likely that you won't need to mess with this.
Everything in this category is TypeScript interfaces, so even if you're implementing a custom transport, you don't need these unless you're using TypeScript.
const {ITransport, ApiRequest, ApiResponse} = require('steam-session');
import {ITransport, ApiRequest, ApiResponse} from 'steam-session';
const {LoginSession} = require('steam-session');
import {LoginSession} from 'steam-session';
The LoginSession
class is the primary way to interact with steam-session.
Read-only. A SteamID
instance containing the SteamID for the
currently-authenticated account. Populated immediately after startWithCredentials
resolves, or immediately after accessToken
or refreshToken
are set.
A number
specifying the time, in milliseconds, before a login attempt will timeout
. The timer begins
after polling
begins.
Read-only. A string
containing your account name. This is populated just before the authenticated
event is fired.
A string
containing your access token. This is populated just before the authenticated
event is
fired. You can also assign an access token to this property if you already have one, although at present that wouldn't
do anything useful.
Setting this property will throw an Error if:
startWithCredentials
and you set it to a token that doesn't belong to the same account, orrefreshToken
and you set this to a token that doesn't belong to the same account as the refresh tokenA string
containing your refresh token. This is populated just before the authenticated
event is
fired. You can also assign a refresh token to this property if you already have one.
Setting this property will throw an Error if:
startWithCredentials
and you set it to a token that doesn't belong to the same account, oraccessToken
and you set this to a token that doesn't belong to the same account as the access tokenplatformType
- A value from EAuthTokenPlatformType
. You should set this to the
appropriate platform type for your desired usage. If omitted, defaults to WebBrowser
.transport
- An ITransport
instance, if you need to specify a custom transport.
If omitted, defaults to a WebApiTransport
instance. In all likelihood, you don't need to use this.Constructs a new LoginSession
instance. Example usage:
import {LoginSession, EAuthTokenPlatformType} from 'steam-session';
let session = new LoginSession(EAuthTokenPlatformType.WebBrowser);
details
- An object with these properties:
accountName
- Your account's login name, as a stringpassword
- Your account's password, as a stringdeviceFriendlyName
- Optional. A name to identify this device. Defaults to the Chrome user-agent.persistence
- Optional. A value from ESessionPersistence. Defaults to Persistent
.websiteId
- Optional. A string containing a valid website ID.steamGuardMachineToken
- Optional. If you have a valid Steam Guard machine token, supplying it here will allow
you to bypass email code verification.steamGuardCode
- Optional. If you have a valid Steam Guard code (either email or TOTP), supplying it here will
attempt to use it during login.Starts a new login attempt using your account credentials. Returns a Promise.
On failure, the Promise will be rejected with its message being equal to the string representation of an EResult
value. There will also be an eresult
property on the Error object equal to the numeric representation of the relevant
EResult value. For example:
Error: InvalidPassword
eresult: 5
On success, the Promise will be resolved with an object containing these properties:
actionRequired
- A boolean indicating whether action is required from you to continue this login attempt.
If false, you should expect for authenticated
to be emitted shortly.validActions
- If actionRequired
is true, this is an array of objects indicating which actions you could take to
continue this login attempt. Each object has these properties:
type
- A value from EAuthSessionGuardTypedetail
- An optional string containing more details about this guard option. Right now, the only known use for
this is that it contains your email address' domain for EAuthSessionGuardType.EmailCode
.Here's a list of which guard types might be present in this method's response, and how you should proceed:
EmailCode
: An email was sent to you containing a code (detail
contains your email address' domain, e.g. gmail.com
).
You should get that code and either call submitSteamGuardCode
, or create a new
LoginSession
and supply that code to the steamGuardCode
property when calling startWithCredentials
.DeviceCode
: You need to supply a TOTP code from your mobile authenticator (or by using steam-totp).
Get that code and either call submitSteamGuardCode
, or create a new LoginSession
and supply that code to the steamGuardCode
property when calling startWithCredentials
.DeviceConfirmation
: You need to approve the confirmation prompt in your Steam mobile app. If this guard type is
present, polling will start and loginTimeout
will be in effect.EmailConfirmation
: You need to approve the confirmation email sent to you. If this guard type is
present, polling will start and loginTimeout
will be in effect.Note that multiple guard types might be available, for example both DeviceCode
and DeviceConfirmation
can be
available at the same time.
When this method resolves, steamID
will be populated.
authCode
- Your Steam Guard code, as a stringIf a Steam Guard code is needed, you can supply it using this method. Returns a Promise.
On failure, the Promise will be rejected with its message being equal to the string representation of an EResult
value. There will also be an eresult
property on the Error object equal to the numeric representation of the relevant
EResult value. For example:
Error: TwoFactorCodeMismatch
eresult: 88
Note that an incorrect email code will fail with EResult value InvalidLoginAuthCode (65), and an incorrect TOTP code will fail with EResult value TwoFactorCodeMismatch (88).
On success, the Promise will be resolved with no value. In this case, you should expect for authenticated
to be emitted shortly.
Cancels polling for an ongoing login attempt. Once canceled, you should no longer interact with this
LoginSession
object, and you should create a new one if you want to start a new attempt.
Once successfully authenticated, you can call this method to get cookies for use on the Steam websites.
You can also manually set refreshToken
and then call this method without going through another login
attempt if you already have a valid refresh token. Returns a Promise.
On failure, the Promise will be rejected. Depending on the nature of the failure, an EResult may or may not be available.
On success, the Promise will be resolved with an array of strings. Each string contains a cookie, e.g.
'steamLoginSecure=blahblahblahblah'
.
This event is emitted once we start polling Steam to periodically check if the login attempt has succeeded or not. Polling starts when any of these conditions are met:
steamGuardCode
*steamGuardMachineToken
*submitSteamGuardCode
*DeviceConfirmation
or EmailConfirmation
are among the valid guards* = in these cases, we expect to only have to poll once before login succeeds.
After this event is emitted, if your loginTimeout
elapses and the login attempt has not yet succeeded,
timeout
is emitted and the login attempt is abandoned. You would then need to start a new login attempt
using a fresh LoginSession
object.
This event is emitted when the time specified by loginTimeout
elapses after polling begins,
and the login attempt has not yet succeeded. When timeout
is emitted, cancelLoginAttempt
is
called internally.
This event is emitted when Steam reports a "remote interaction" via polling. This is observed to happen
when the approval prompt is viewed in the Steam mobile app for the DeviceConfirmation
guard.
This event is emitted when we successfully authenticate with Steam. At this point, accountName
,
accessToken
, and refreshToken
are populated. If the EAuthTokenPlatformType
passed to the constructor is appropriate, you can now safely call getWebCookies
.
This event is emitted if we encounter an error while polling. The first argument to the event handler is an Error object. If this happens, the login attempt has failed and will need to be retried.
Node.js will crash if this event is emitted and not handled.
FAQs
Enables authenticating with Steam
The npm package steam-session receives a total of 6,516 weekly downloads. As such, steam-session popularity was classified as popular.
We found that steam-session demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.