node-steamcommunity/components/webapi.js

25 lines
561 B
JavaScript
Raw Normal View History

2015-11-27 14:28:31 +08:00
var SteamCommunity = require('../index.js');
SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
var self = this;
if( this.oAuthToken ) {
return callback( null, this.oAuthToken );
}
2015-11-27 14:28:31 +08:00
// 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]);
});
};