This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
steam_server.js
67 lines (57 loc) · 2.04 KB
/
steam_server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Steam = {};
Oauth.registerService('steam', 2, null, function(query) {
// XX fix the state
query.state = _.last(query['openid.return_to'].split('?close&'));
var steamId = getSteamId(query);
var identity = getIdentity(steamId);
return {
serviceData: {
id: identity.steamid,
username: identity.personaname,
avatar: {
small: identity.avatar,
medium: identity.avatarmedium,
full: identity.avatarfull
}
},
options: {profile: { name: identity.personaname }}
};
});
var getSteamId = function (query) {
var config = ServiceConfiguration.configurations.findOne({service: 'steam'});
if (!config)
throw new ServiceConfiguration.ConfigError("Service not configured");
var response;
try {
response = HTTP.post("https://steamcommunity.com/openid/login", { params: _.extend(query, { 'openid.mode': 'check_authentication' }) });
} catch (err) {
throw _.extend(new Error("Failed to complete OAuth handshake with Steam. " + err.message), { response: err.response });
}
if (response.content && response.content.indexOf("is_valid:true") !== -1) {
// Grab the SteamID from the claimed_id
return _.last(query['openid.claimed_id'].split('/'));
} else {
throw new Error("Failed to complete OAuth handshake with Steam. " + response.data.error);
}
};
var getIdentity = function (steamId) {
var config = ServiceConfiguration.configurations.findOne({service: 'steam'});
if (!config)
throw new ServiceConfiguration.ConfigError("Service not configured");
var response;
try {
response = HTTP.get("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/", {
params: {
key: config.apiKey,
steamids: steamId
}
});
// Return the first player
return _.first(response.data.response.players);
} catch (err) {
throw _.extend(new Error("Failed to fetch identity from Steam. " + err.message), { response: err.response });
}
};
Steam.retrieveCredential = function(credentialToken) {
return Oauth.retrieveCredential(credentialToken);
};