Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement openID login #296

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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;
}

Revadike marked this conversation as resolved.
Show resolved Hide resolved
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