/
steam-signin.js
37 lines (28 loc) · 1.19 KB
/
steam-signin.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
const HTTP = require('http');
// Comment the next line and uncomment the following line if you aren't running this example from inside the repository
const SteamSignIn = require('../index.js');
//const SteamSignIn = require('steam-signin');
let g_ServerListenPort = null;
let server = HTTP.createServer(async (req, res) => {
let signIn = new SteamSignIn('http://localhost');
if (req.url.startsWith('/return')) {
// Always return a plaintext response to this route
res.setHeader('Content-Type', 'text/plain');
try {
let steamId = await signIn.verifyLogin(req.url);
res.end(`Your SteamID is: ${steamId.getBigIntID()} / ${steamId.steam3()}`);
console.log(`User signed in: ${steamId.getBigIntID()} / ${steamId.steam3()}`);
} catch (ex) {
res.end(`Failed to validate your login: ${ex.message}`);
}
return;
}
// Redirect to Steam for all routes except /return
res.statusCode = 302;
res.setHeader('Location', signIn.getUrl(`http://localhost:${g_ServerListenPort}/return`));
res.end();
});
server.listen(() => {
g_ServerListenPort = server.address().port;
console.log(`HTTP server started. Open http://localhost:${g_ServerListenPort} in your browser to demo Steam sign-in.`);
});