forked from game-ci/steam-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtotp.js
30 lines (25 loc) · 876 Bytes
/
totp.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
const totp = require('steam-totp');
function run() {
// Get shared secret from environment variable
const sharedSecret = process.env.steam_shared_secret;
if (!sharedSecret) {
console.error('Error: steam_shared_secret environment variable is not set.');
process.exit(1);
}
// Validate the shared secret format
if (sharedSecret.length !== 28 || !sharedSecret.endsWith('=')) {
console.error('Error: Invalid shared secret.');
process.exit(1);
}
// Get the time offset and generate the TOTP code
totp.getTimeOffset((error, offset) => {
if (error) {
console.error(`Error retrieving time offset: ${error}`);
process.exit(1);
}
const code = totp.generateAuthCode(sharedSecret, offset);
console.log(code);
process.exit(0);
});
}
run();