Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,54 @@ SteamCommunity.prototype.oAuthLogin = function(steamguard, token, callback) {
}, "steamcommunity");
};

/**
* Sign in through Steam on a third party website via OpenID.
* @param {string} url - The Steam OpenID login URL to the third party website.
* @param {function} callback
*/
SteamCommunity.prototype.openidLogin = function(url, callback) {
var self = this;
self.httpRequestGet({
"uri": url,
"followAllRedirects": true
}, function(err, response, body) {
if(err) {
callback(err);
return;
}

var { host, pathname } = response.request.uri;
if (host !== 'steamcommunity.com' || !pathname.startWith('/openid/login')) {
callback(new Error(`Unexpected redirect to ${host}${pathname} (expected steamcommunity.com/openid/login)`));
return;
}

var $ = Cheerio.load(body);
var form = $('#openidForm');
if (!form) { // Should exist, even if not logged in
callback(new Error('Malformed response'));
return;
}

if ($('.OpenID_loggedInText').length === 0) {
callback(new Error('Not Logged In'));
return;
}

var values = {};
form.serializeArray().forEach(function(item) {
values[item.name] = item.value;
});

self.httpRequestPost("https://steamcommunity.com/openid/login/", {
"formData": values,
"followAllRedirects": true
}, callback);
});
};

SteamCommunity.prototype.signInThroughSteam = SteamCommunity.prototype.openidLogin;

/**
* Get a token that can be used to log onto Steam using steam-user.
* @param {function} callback
Expand Down