Added getWebApiOauthToken

This commit is contained in:
Alexander Corn 2015-11-27 01:28:31 -05:00
parent efea8c6265
commit 2399a5b783
3 changed files with 27 additions and 14 deletions

View File

@ -40,17 +40,9 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
this.chatState = SteamCommunity.ChatState.LoggingOn;
var self = this;
this.request("https://steamcommunity.com/chat", function(err, response, body) {
if(err || response.statusCode != 200) {
self.emit('debug', 'Error requesting chat WebAPI token: ' + (err ? err.message : "HTTP error " + response.statusCode));
self.chatState = SteamCommunity.ChatState.LogOnFailed;
setTimeout(self.chatLogon.bind(self), 5000);
return;
}
var match = body.match(/[0-9a-f]{32}/);
if(!match) {
self.emit('debug', 'Couldn\'t find a WebAPI chat token in the response.');
this.getWebApiOauthToken(function(err, token) {
if(err) {
self.emit('debug', "Cannot get oauth token: " + err.message);
self.chatState = SteamCommunity.ChatState.LogOnFailed;
setTimeout(self.chatLogon.bind(self), 5000);
return;
@ -60,7 +52,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
"uri": "https://api.steampowered.com/ISteamWebUserPresenceOAuth/Logon/v1",
"form": {
"ui_mode": uiMode,
"access_token": match[0]
"access_token": token
},
"json": true
}, function(err, response, body) {
@ -81,7 +73,7 @@ SteamCommunity.prototype.chatLogon = function(interval, uiMode) {
self._chat = {
"umqid": body.umqid,
"message": body.message,
"accessToken": match[0],
"accessToken": token,
"interval": interval
};

20
components/webapi.js Normal file
View File

@ -0,0 +1,20 @@
var SteamCommunity = require('../index.js');
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
var self = this;
// Pull an oauth token from the webchat UI
this.request("https://steamcommunity.com/chat", function(err, response, body) {
if(self._checkHttpError(err, response, callback)) {
return;
}
var match = body.match(/"([0-9a-f]{32})"/);
if (!match) {
callback(new Error("Malformed response"));
return;
}
callback(null, match[1]);
});
};

View File

@ -145,7 +145,7 @@ SteamCommunity.prototype.getSessionID = function() {
function generateSessionID() {
return Math.floor(Math.random() * 1000000000);
};
}
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
var self = this;
@ -333,6 +333,7 @@ require('./components/market.js');
require('./components/groups.js');
require('./components/users.js');
require('./components/inventoryhistory.js');
require('./components/webapi.js');
require('./classes/CMarketItem.js');
require('./classes/CMarketSearchResult.js');
require('./classes/CSteamGroup.js');