From 4710afa28b5cf5d064a30a17191f9c4badb02f77 Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Wed, 13 Feb 2019 17:40:45 -0500 Subject: [PATCH] Added getClientLogonToken --- index.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index c7a2632..2409519 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ module.exports = SteamCommunity; SteamCommunity.SteamID = SteamID; SteamCommunity.ConfirmationType = require('./resources/EConfirmationType.js'); -SteamCommunity.EResult = require('./resources/EResult.js') +SteamCommunity.EResult = require('./resources/EResult.js'); function SteamCommunity(options) { @@ -249,6 +249,36 @@ SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) { }, "steamcommunity"); }; +/** + * Get a token that can be used to log onto Steam using steam-user. + * @param {function} callback + */ +SteamCommunity.prototype.getClientLogonToken = function(callback) { + this.httpRequestGet({ + "uri": "https://steamcommunity.com/chat/clientjstoken", + "json": true + }, (err, res, body) => { + if (err || res.statusCode != 200) { + callback(err ? err : new Error('HTTP error ' + res.statusCode)); + return; + } + + if (!body.logged_in) { + let e = new Error('Not Logged In'); + callback(e); + this._notifySessionExpired(e); + return; + } + + if (!body.account_name || !body.token) { + callback(new Error('Malformed response')); + return; + } + + callback(null, body); + }); +}; + SteamCommunity.prototype._setCookie = function(cookie, secure) { var protocol = secure ? "https" : "http"; cookie.secure = !!secure;