Skip to content

Commit

Permalink
JWT reader
Browse files Browse the repository at this point in the history
  • Loading branch information
kaihaase committed Dec 13, 2023
1 parent 91e64db commit 623827d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lenne.tech/cli",
"version": "0.0.96",
"version": "0.0.97",
"description": "lenne.Tech CLI: lt",
"keywords": [
"lenne.Tech",
Expand Down
48 changes: 48 additions & 0 deletions src/commands/tools/jwt-read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { GluegunCommand } from 'gluegun';
import { ExtendedGluegunToolbox } from '../../interfaces/extended-gluegun-toolbox';

/**
* Parse a JWT and show the payload
*/
const NewCommand: GluegunCommand = {
name: 'jwt-read',
alias: ['jr'],
description: 'Parse a JWT and show the payload',
hidden: false,
run: async (toolbox: ExtendedGluegunToolbox) => {
const {
helper,
print: { info, error },
parameters,
} = toolbox;

const jwt = await helper.getInput(parameters.first, {
name: 'JWT to parse',
showError: false,
});

if (!jwt) {
error('No JWT provided');
return;
}

// Hash password
const data = JSON.parse(Buffer.from(jwt.split('.')[1], 'base64').toString())
info(data);
if (data.iat) {
info('iat: ' + new Date(data.iat * 1000));
}
if (data.exp) {
info('exp: ' + new Date(data.exp * 1000));
}

if (!toolbox.parameters.options.fromGluegunMenu) {
process.exit();
}

// For tests
return `jwt-read`;
},
};

export default NewCommand;

0 comments on commit 623827d

Please sign in to comment.