-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
executable file
·46 lines (40 loc) · 1.05 KB
/
index.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
#! /usr/bin/env node
const {
outputHeader,
outputHelp,
outputJwtIoLink,
outputNicePayloadDates,
outputPayload,
outputSignature,
outputTokenAsJson,
outputVersion,
} = require("./src/output.js");
const { getToken, getArgument } = require("./src/input.js");
const { decodeToken } = require("./src/jwt.js");
(async () => {
const token = await getToken(process);
const secret = getArgument("secret");
const output = getArgument("output");
const versionFlag = getArgument("version");
const helpFlag = getArgument("help");
const decodedToken = decodeToken(token, secret);
if (versionFlag) {
outputVersion();
process.exit(0);
}
if (helpFlag) {
outputHelp();
process.exit(0);
}
if (token === undefined) {
process.exit(1);
} else if (output == "json") {
outputTokenAsJson(decodedToken);
} else {
outputJwtIoLink(token);
outputHeader(decodedToken.header);
outputPayload(decodedToken.payload);
outputNicePayloadDates(decodedToken.payload);
outputSignature(decodedToken.signature);
}
})();