mirror of
https://github.com/DoctorMcKay/node-steamcommunity.git
synced 2025-01-01 10:42:49 +08:00
Add disableMobile flag to login() so user has option to not pretend we're logging in from a phone
This commit is contained in:
parent
4542793175
commit
c6ab392c37
86
index.js
86
index.js
@ -64,22 +64,27 @@ SteamCommunity.prototype.login = function(details, callback) {
|
|||||||
var parts = details.steamguard.split('||');
|
var parts = details.steamguard.split('||');
|
||||||
this._setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), true);
|
this._setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var disableMobile = details.disableMobile;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Delete the cache
|
// Delete the cache
|
||||||
delete self._profileURL;
|
delete self._profileURL;
|
||||||
|
|
||||||
// headers required to convince steam that we're logging in from a mobile device so that we can get the oAuth data
|
// headers required to convince steam that we're logging in from a mobile device so that we can get the oAuth data
|
||||||
var mobileHeaders = {
|
var mobileHeaders = {};
|
||||||
"X-Requested-With": "com.valvesoftware.android.steam.community",
|
if(!disableMobile){
|
||||||
"Referer": "https://steamcommunity.com/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client",
|
mobileHeaders = {
|
||||||
"User-Agent": "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
|
"X-Requested-With": "com.valvesoftware.android.steam.community",
|
||||||
"Accept": "text/javascript, text/html, application/xml, text/xml, */*"
|
"Referer": "https://steamcommunity.com/mobilelogin?oauth_client_id=DE45CD61&oauth_scope=read_profile%20write_profile%20read_client%20write_client",
|
||||||
};
|
"User-Agent": "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
|
||||||
|
"Accept": "text/javascript, text/html, application/xml, text/xml, */*"
|
||||||
|
};
|
||||||
|
|
||||||
this._setCookie(Request.cookie("mobileClientVersion=0 (2.1.3)"));
|
this._setCookie(Request.cookie("mobileClientVersion=0 (2.1.3)"));
|
||||||
this._setCookie(Request.cookie("mobileClient=android"));
|
this._setCookie(Request.cookie("mobileClient=android"));
|
||||||
|
}
|
||||||
|
|
||||||
this.httpRequestPost("https://steamcommunity.com/login/getrsakey/", {
|
this.httpRequestPost("https://steamcommunity.com/login/getrsakey/", {
|
||||||
"form": {"username": details.accountName},
|
"form": {"username": details.accountName},
|
||||||
@ -101,25 +106,30 @@ SteamCommunity.prototype.login = function(details, callback) {
|
|||||||
|
|
||||||
var key = new RSA();
|
var key = new RSA();
|
||||||
key.setPublic(body.publickey_mod, body.publickey_exp);
|
key.setPublic(body.publickey_mod, body.publickey_exp);
|
||||||
|
|
||||||
|
var formObj = {
|
||||||
|
"captcha_text": details.captcha || "",
|
||||||
|
"captchagid": self._captchaGid,
|
||||||
|
"emailauth": details.authCode || "",
|
||||||
|
"emailsteamid": "",
|
||||||
|
"password": hex2b64(key.encrypt(details.password)),
|
||||||
|
"remember_login": "true",
|
||||||
|
"rsatimestamp": body.timestamp,
|
||||||
|
"twofactorcode": details.twoFactorCode || "",
|
||||||
|
"username": details.accountName,
|
||||||
|
"loginfriendlyname": "#login_emailauth_friendlyname_mobile",
|
||||||
|
"donotcache": Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
if(!disableMobile){
|
||||||
|
formObj.oauth_client_id = "DE45CD61";
|
||||||
|
formObj.oauth_scope = "read_profile write_profile read_client write_client";
|
||||||
|
}
|
||||||
|
|
||||||
self.httpRequestPost({
|
self.httpRequestPost({
|
||||||
"uri": "https://steamcommunity.com/login/dologin/",
|
"uri": "https://steamcommunity.com/login/dologin/",
|
||||||
"json": true,
|
"json": true,
|
||||||
"form": {
|
"form": formObj,
|
||||||
"captcha_text": details.captcha || "",
|
|
||||||
"captchagid": self._captchaGid,
|
|
||||||
"emailauth": details.authCode || "",
|
|
||||||
"emailsteamid": "",
|
|
||||||
"password": hex2b64(key.encrypt(details.password)),
|
|
||||||
"remember_login": "true",
|
|
||||||
"rsatimestamp": body.timestamp,
|
|
||||||
"twofactorcode": details.twoFactorCode || "",
|
|
||||||
"username": details.accountName,
|
|
||||||
"oauth_client_id": "DE45CD61",
|
|
||||||
"oauth_scope": "read_profile write_profile read_client write_client",
|
|
||||||
"loginfriendlyname": "#login_emailauth_friendlyname_mobile",
|
|
||||||
"donotcache": Date.now()
|
|
||||||
},
|
|
||||||
"headers": mobileHeaders
|
"headers": mobileHeaders
|
||||||
}, function(err, response, body) {
|
}, function(err, response, body) {
|
||||||
deleteMobileCookies();
|
deleteMobileCookies();
|
||||||
@ -148,20 +158,32 @@ SteamCommunity.prototype.login = function(details, callback) {
|
|||||||
callback(error);
|
callback(error);
|
||||||
} else if(!body.success) {
|
} else if(!body.success) {
|
||||||
callback(new Error(body.message || "Unknown error"));
|
callback(new Error(body.message || "Unknown error"));
|
||||||
} else if(!body.oauth) {
|
} else if(!disableMobile && !body.oauth) {
|
||||||
callback(new Error("Malformed response"));
|
callback(new Error("Malformed response"));
|
||||||
} else {
|
} else {
|
||||||
var sessionID = generateSessionID();
|
var sessionID = generateSessionID(), oAuth;
|
||||||
var oAuth = JSON.parse( body.oauth );
|
|
||||||
self._setCookie(Request.cookie('sessionid=' + sessionID));
|
self._setCookie(Request.cookie('sessionid=' + sessionID));
|
||||||
|
|
||||||
self.steamID = new SteamID(oAuth.steamid);
|
|
||||||
self.oAuthToken = oAuth.oauth_token;
|
|
||||||
|
|
||||||
var cookies = self._jar.getCookieString("https://steamcommunity.com").split(';').map(function(cookie) {
|
var cookies = self._jar.getCookieString("https://steamcommunity.com").split(';').map(function(cookie) {
|
||||||
return cookie.trim();
|
return cookie.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(!disableMobile){
|
||||||
|
oAuth = JSON.parse( body.oauth );
|
||||||
|
self.steamID = new SteamID(oAuth.steamid);
|
||||||
|
self.oAuthToken = oAuth.oauth_token;
|
||||||
|
}else{
|
||||||
|
for(var i = 0; i < cookies.length; i++) {
|
||||||
|
var parts = cookies[i].split('=');
|
||||||
|
if(parts[0] == 'steamLogin') {
|
||||||
|
self.steamID = new SteamID(decodeURIComponent(parts[1]).split('||')[0])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.oAuthToken = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the Steam Guard cookie
|
// Find the Steam Guard cookie
|
||||||
var steamguard = null;
|
var steamguard = null;
|
||||||
for(var i = 0; i < cookies.length; i++) {
|
for(var i = 0; i < cookies.length; i++) {
|
||||||
@ -174,7 +196,7 @@ SteamCommunity.prototype.login = function(details, callback) {
|
|||||||
|
|
||||||
self.setCookies(cookies);
|
self.setCookies(cookies);
|
||||||
|
|
||||||
callback(null, sessionID, cookies, steamguard, oAuth.oauth_token);
|
callback(null, sessionID, cookies, steamguard, disableMobile ? null : oAuth.oauth_token);
|
||||||
}
|
}
|
||||||
}, "steamcommunity");
|
}, "steamcommunity");
|
||||||
}, "steamcommunity");
|
}, "steamcommunity");
|
||||||
|
Loading…
Reference in New Issue
Block a user