Steam Session Manager
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 (you may want to consider using
steam-signin) and the many available WebAPIs.
Node.js v12.22.0 or later is required to use this module.
Concepts
Logging into Steam is a two-step process.
- You start a login session either using your account credentials (username and password) or by generating a QR code
- Assuming any credentials you provided when you started the session were correct, Steam replies with a list of login guards
- See EAuthSessionGuardType
- If your account doesn't have Steam Guard enabled or you provided a valid code upfront, there may be 0 guards required
- Only one guard must be satisfied to complete the login. For example, you might be given a choice of providing a TOTP code or confirming the login in your Steam mobile app
- When you satisfy any guards, Steam sends back an access token and a refresh token. These can be used to:
Example Code
See the examples directory on GitHub for example code.
Exports
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 enums, and the LoginSession
and potentially LoginApprover classes.
Enums
EAuthSessionSecurityHistory
const {EAuthSessionSecurityHistory} = require('steam-session');
import {EAuthSessionSecurityHistory} from 'steam-session';
View on GitHub
EAuthSessionGuardType
const {EAuthSessionGuardType} = require('steam-session');
import {EAuthSessionGuardType} from 'steam-session';
View on GitHub
Contains the possible auth session guards.
EAuthTokenPlatformType
const {EAuthTokenPlatformType} = require('steam-session');
import {EAuthTokenPlatformType} from 'steam-session';
View on GitHub
Contains the different platform types that can be authenticated for. You should specify the correct platform type when
you instantiate a LoginSession object.
Audiences present in tokens issued for the different platform types:
SteamClient - ['web', 'client']
WebBrowser - ['web']
MobileApp - ['web', 'mobile']
EResult
const {EResult} = require('steam-session');
import {EResult} from 'steam-session';
View on GitHub
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.
ESessionPersistence
const {ESessionPersistence} = require('steam-session');
import {ESessionPersistence} from 'steam-session';
View on GitHub
Contains possible persistence levels for auth sessions.
Custom Transports
It's possible to define a custom transport to be used when interacting with the Steam login server. The default transport
used to interact with the Steam login server is chosen depending on your provided EAuthTokenPlatformType.
For the SteamClient platform type, a WebSocketCMTransport will be used to communicate with a CM server using a WebSocket.
For other platform types, a 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';
View on GitHub
LoginSession
const {LoginSession} = require('steam-session');
import {LoginSession} from 'steam-session';
The LoginSession class is the primary way to interact with steam-session.
Properties
steamID
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 (meaning that
this is always populated when authenticated fires).
loginTimeout
A number specifying the time, in milliseconds, before a login attempt will timeout. The timer begins
after polling begins.
If you attempt to set this property after polling has already been emitted, an Error will be thrown since
setting this property after that point has no effect.
accountName
Read-only. A string containing your account name. This is populated just before the authenticated
event is fired.
accessToken
A string containing your access token.
As of 2023-09-12, Steam does not return an access token in response to successful authentication, so this won't be set
when the authenticated event is fired. (this behavior has been reverted)
This will be set after you call refreshAccessToken() or renewRefreshToken().
Also, since getWebCookies() calls refreshAccessToken() internally for EAuthTokenPlatformType
SteamClient or MobileApp, this will also be set after calling getWebCookies() for those platform types.
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:
- You set it to a token that isn't well-formed, or
- You set it to a refresh token rather than an access token, or
- You have already called
startWithCredentials and you set it to a token that doesn't belong to the same account, or
- You have already set
refreshToken and you set this to a token that doesn't belong to the same account as the refresh token
Access tokens can't be used for much. You can use them with a few undocumented WebAPIs like
IFriendsListService/GetFriendsList by passing the access
token as an access_token query string parameter. For example:
https://api.steampowered.com/IFriendsListService/GetFriendsList/v1/?access_token=eyAidHlwIjogIkpXVCIsICJhbGciOiAiRWREU0EiIH0.eyJpc3MiOiJ...
As of time of writing (2023-04-24), it appears that you can also use access tokens with regular published API methods,
for example:
https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid=440&access_token=eyAidHlwIjogIkpXVCIsICJhbGciOiAiRWREU0EiIH0.eyJpc3MiOiJ...
refreshToken
A 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:
- You set it to a token that isn't well-formed, or
- You set it to an access token rather than a refresh token, or
- You have already called
startWithCredentials and you set it to a token that doesn't belong to the same account, or
- You have already set
accessToken and you set this to a token that doesn't belong to the same account as the access token
steamGuardMachineToken
Read-only. A string containing your Steam Guard machine token. This is populated when you pass a steamGuardMachineToken to
startWithCredentials, or just before the steamGuardMachineToken
event is emitted.
Methods
Constructor(platformType[, options])
platformType - A value from EAuthTokenPlatformType. You should set this to the
appropriate platform type for your desired usage.
options