Skip to content

Commit

Permalink
Added new webLogOn method to API.
Browse files Browse the repository at this point in the history
  • Loading branch information
scholtzm committed Jul 26, 2015
1 parent f8ad02d commit fcf0da3
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 18 deletions.
22 changes: 19 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* [.removeAllHandlers(options)](#API+removeAllHandlers)
* [.getDataFolderPath()](#API+getDataFolderPath) ⇒ <code>string</code>
* [.getLogger()](#API+getLogger) ⇒ <code>Object</code>
* [.webLogOn()](#API+webLogOn)

<a name="new_API_new"></a>
### new API(Vapor, pluginName)
Expand Down Expand Up @@ -65,13 +66,14 @@ Returns active Steam handler used by Vapor.

<a name="API+getUtils"></a>
### apI.getUtils() ⇒ <code>Object</code>
Returns Utils class.
Returns instance of Utils class.

**Kind**: instance method of <code>[API](#API)</code>
**Returns**: <code>Object</code> - Instantiated Utils class.
<a name="API+getSteam"></a>
### apI.getSteam() ⇒ <code>Object</code>
Returns Steam object.

This is useful for all the ESomething enums.

**Kind**: instance method of <code>[API](#API)</code>
Expand Down Expand Up @@ -155,6 +157,20 @@ Returns logger prefixed with plugin's name.

**Kind**: instance method of <code>[API](#API)</code>
**Returns**: <code>Object</code> - Logger.
<a name="API+webLogOn"></a>
### apI.webLogOn()
Calls Vapor's internal webLogOn method.

Listen to `cookies` event to receive new array of cookies.

You should call this function ONLY if you believe cookies have expired, e.g.
you logged into your account from another IP / browser and you are getting
HTTP 403 etc.

You do NOT have to call this method on startup as it's automatically called
by Vapor after successfully logging in.

**Kind**: instance method of <code>[API](#API)</code>
<a name="Utils"></a>
## Utils
**Kind**: global class
Expand Down Expand Up @@ -280,7 +296,8 @@ Converts 64 bit SteamID string to account ID.
### utils.getTimestamp(unixTimestamp, format) ⇒ <code>string</code>
Converts unix timestamp into formatted timestamp.

The timestamp format is taken from Vapor's logs configuration.
The timestamp format is taken from Vapor's logs configuration
if not provided.

**Kind**: instance method of <code>[Utils](#Utils)</code>
**Returns**: <code>string</code> - Formatted timestamp.
Expand All @@ -289,4 +306,3 @@ The timestamp format is taken from Vapor's logs configuration.
| --- | --- | --- |
| unixTimestamp | <code>number</code> | Unix timestamp. |
| format | <code>string</code> | Timestamp format. |

8 changes: 8 additions & 0 deletions docs/EVENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Vapor Events

Vapor emits events and any plugin can register appropriate callback function.

Event | Callback arguments | Description
----- | ---- | -----------
ready | - | Vapor has completely logged into Steam network.
cookies | cookies | Array of cookies provided by Steam's `ISteamUserAuth/AuthenticateUser/v1` web API method. This event is emitted automatically by Vapor after successful login. This functionality was previously provided by node-steam's `webLogOn` method.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ Docs in this folder are automatically generated.
* Description of Utils class methods and properties
* __BUILT-IN-PLUGINS.md__
* List of built-in plugins and their descriptions
* __EVENTS.md__
* Description of Vapor's internal events
21 changes: 20 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ API.prototype.getHandler = function(handler) {
};

/**
* Returns Utils class.
* Returns instance of Utils class.
* @return {Object} Instantiated Utils class.
*/
API.prototype.getUtils = function() {
Expand All @@ -79,6 +79,7 @@ API.prototype.getUtils = function() {

/**
* Returns Steam object.
*
* This is useful for all the ESomething enums.
* @return {Object} Steam.
*/
Expand Down Expand Up @@ -272,3 +273,21 @@ API.prototype.getLogger = function() {
info: function(message) { log.info(prefix + message); }
};
};

/**
* Calls Vapor's internal webLogOn method.
*
* Listen to `cookies` event to receive new array of cookies.
*
* You should call this function ONLY if you believe cookies have expired, e.g.
* you logged into your account from another IP / browser and you are getting
* HTTP 403 etc.
*
* You do NOT have to call this method on startup as it's automatically called
* by Vapor after successfully logging in.
*/
API.prototype.webLogOn = function() {
_vapor.steamUser.requestWebAPIAuthenticateUserNonce(function(nonce) {
this.webLogOn(nonce.webapi_authenticate_user_nonce);
}.bind(_vapor));
};
6 changes: 1 addition & 5 deletions lib/handlers/logOnResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ module.exports = function(response) {
self.emit('ready');

// Call web login
self.webLogOn(response.webapi_authenticate_user_nonce, function(cookies) {
self.log.info("Received new web cookies.");
self.cookies = cookies;
self.emit('cookies', cookies);
});
self.webLogOn(response.webapi_authenticate_user_nonce);

// Auth code needed
} else if(response.eresult === Steam.EResult.AccountLogonDenied ||
Expand Down
19 changes: 11 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var fs = require('fs');
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var https = require('https');
var crypto = require('crypto');

var Steam = require('steam');
var SteamGroups = require('steam-groups');
Expand Down Expand Up @@ -122,9 +123,8 @@ Vapor.prototype.shutdown = function() {
*
* Adopted from node-steam v0.6.8 by seishun.
* @param {string} webLoginKey Login key provided by the logOn method.
* @param {Function} callback Callback function which receives the cookie array.
*/
Vapor.prototype.webLogOn = function(webLoginKey, callback) {
Vapor.prototype.webLogOn = function(webLoginKey) {
var self = this;

var sessionKey = SteamCrypto.generateSessionKey();
Expand All @@ -147,25 +147,28 @@ Vapor.prototype.webLogOn = function(webLoginKey, callback) {
if (res.statusCode === 200) {
res.on('data', function(chunk) {
var response = JSON.parse(chunk);
var sessionID = Math.floor(Math.random() * 1000000000).toString();

callback([
'sessionid=' + sessionID,
var cookies = [
'sessionid=' + crypto.randomBytes(12).toString('hex'),
'steamLogin=' + response.authenticateuser.token,
'steamLoginSecure=' + response.authenticateuser.tokensecure
]);
];

self.log.info("Received new web cookies.");
self.cookies = cookies;
self.emit('cookies', cookies);
});
} else {
self.steamUser.requestWebAPIAuthenticateUserNonce(function(nonce) {
self.webLogOn(nonce.webapi_authenticate_user_nonce, callback);
self.webLogOn(nonce.webapi_authenticate_user_nonce);
});

return;
}
});

req.on('error', function() {
self.webLogOn(webLoginKey, callback);
self.webLogOn(webLoginKey);
});

req.end(data);
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ Utils.prototype.steamIDToAccountID = function(steamID) {
/**
* Converts unix timestamp into formatted timestamp.
*
* The timestamp format is taken from Vapor's logs configuration.
* The timestamp format is taken from Vapor's logs configuration
* if not provided.
* @param {number} unixTimestamp Unix timestamp.
* @param {string} format - Timestamp format.
* @return {string} Formatted timestamp.
Expand Down

0 comments on commit fcf0da3

Please sign in to comment.