-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from akdombrowski/1.0.40
1.0.40
- Loading branch information
Showing
13 changed files
with
1,705 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env" | ||
], | ||
"presets": ["@babel/preset-env"], | ||
"env": { | ||
"test": { | ||
"plugins": [ | ||
"istanbul" | ||
] | ||
"plugins": ["istanbul"] | ||
} | ||
} | ||
} | ||
}, | ||
"plugins": ["@babel/plugin-transform-runtime"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,16 @@ | |
![GitHub Repo stars](https://img.shields.io/github/stars/akdombrowski/jwt-authn?style=for-the-badge&logo=github) | ||
![GitHub forks](https://img.shields.io/github/forks/akdombrowski/jwt-authn?style=for-the-badge&logo=github) | ||
![GitHub watchers](https://img.shields.io/github/watchers/akdombrowski/jwt-authn?style=for-the-badge&logo=github) | ||
[![](https://data.jsdelivr.com/v1/package/npm/jwt-authn/badge)](https://www.jsdelivr.com/package/npm/jwt-authn) | ||
|
||
[![Rate on Openbase](https://badges.openbase.com/js/rating/jwt-authn.svg)](https://openbase.com/js/jwt-authn?utm_source=embedded&utm_medium=badge&utm_campaign=rate-badge) | ||
|
||
# jwt-authn | ||
|
||
jwt-authn is an npm package for dealing with JSON Web Tokens (JWT). Encoding, decoding, verifying, signing, and more coming. It includes support for the RS256 and HS256 algorithms and JWK and PEM format keys (even encrypted keys). Only Node >=15.x as a requirement! | ||
|
||
Now with command line support! | ||
|
||
jwt-authn is an npm package for dealing with JSON Web Tokens. Encoding, decoding, verifying, signing, and more coming. It includes support for the RS256 and HS256 algorithms and JWK and PEM format keys (even encrypted keys). No package dependencies! Its only dependency is NodeJS itself. | ||
|
||
|
||
*[Must be on Node >= 15.x](https://nodejs.org/en/about/releases/) | ||
|
@@ -25,6 +30,7 @@ jwt-authn is an npm package for dealing with JSON Web Tokens. Encoding, decoding | |
- [⬆Usage](#usage) | ||
- [⬆Installation:](#installation) | ||
- [⬆Accepted Form of JWTs](#accepted-form-of-jwts) | ||
- [⬆ CLI support for JWT Decoding](#-cli-support-for-jwt-decoding) | ||
- [⬆ Decoding a JWT](#-decoding-a-jwt) | ||
- [⬆ **jwtDecode(jwt)**](#-jwtdecodejwt) | ||
- [⬆ Encoding a JWT](#-encoding-a-jwt) | ||
|
@@ -60,10 +66,27 @@ Use the package manager [npm](https://www.npmjs.com/) or [yarn](https://yarnpkg. | |
npm install jwt-authn | ||
``` | ||
|
||
|
||
```Shell | ||
yarn add jwt-authn | ||
``` | ||
|
||
Or from a cdn: | ||
``` | ||
https://cdn.jsdelivr.net/npm/[email protected]/lib | ||
``` | ||
|
||
If using for the command line support (or it'll only be available in the current directory's node_modules folder): | ||
|
||
```Shell | ||
npm install -g jwt-authn | ||
``` | ||
|
||
```Shell | ||
yarn global install jwt-authn | ||
``` | ||
|
||
|
||
<br> | ||
|
||
--- | ||
|
@@ -92,6 +115,34 @@ eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTk | |
|
||
--- | ||
|
||
### [⬆](#index) CLI support for JWT Decoding | ||
|
||
<br> | ||
|
||
Running just jwt-authn will try to decode whatever is in your clipboard. | ||
```Shell | ||
# Decodes what's in your clipboard. | ||
jwt-authn | ||
``` | ||
|
||
Alternatively, you can run jwt-authn with the clipboard option. | ||
```Shell | ||
jwt-authn -c | ||
``` | ||
|
||
```Shell | ||
jwt-authn --clipboard | ||
``` | ||
|
||
or to decode the input | ||
```Shell | ||
jwt-authn eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk | ||
``` | ||
|
||
<br> | ||
|
||
--- | ||
|
||
### [⬆](#index) Decoding a JWT | ||
|
||
<br> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env node | ||
|
||
import { jwtDecode } from "../lib"; | ||
import clipboardy from "clipboardy"; | ||
|
||
const decode = async (jwt) => { | ||
try { | ||
const decoded = await jwtDecode(jwt); | ||
return decoded; | ||
} catch (e) { | ||
throw e; | ||
} | ||
}; | ||
|
||
export const HELP_TEXT = | ||
"******HELP*****\n\ | ||
use -c or --clipboard or call command with no arguments to decode the JWT in your clipboard\n\ | ||
or call command with JWT as first argument\n\ | ||
****************"; | ||
|
||
export const cli = async (clipboard, argv) => { | ||
// read passed in argument | ||
let arg2; | ||
if (argv) { | ||
arg2 = argv[2]; | ||
} | ||
|
||
if (arg2 == "-h" || arg2 === "--help") { | ||
// Help display | ||
console.log(HELP_TEXT); | ||
return HELP_TEXT; | ||
} else if (arg2 === "-c" || arg2 === "--clipboard" || !arg2) { | ||
// Check for something in the clipboard. | ||
if (clipboard) { | ||
// Great, there's something in the clipboard. Let's try to decode it as a | ||
// JWT. | ||
try { | ||
const decoded = await decode(clipboard); | ||
// Show what we found in the clipboard | ||
console.log("Decoding: "); | ||
console.log(clipboard); | ||
// Show the decoded jwt. | ||
console.log(decoded); | ||
return decoded; | ||
} catch (e) { | ||
console.error("I found an error :("); | ||
console.error( | ||
"Couldn't decode what was in clipboard. Pass in a JWT as the first argument or copy a JWT to your clipboard" | ||
); | ||
console.error("what's on your clipboard? "); | ||
console.error(clipboard); | ||
throw e; | ||
} | ||
} else { | ||
console.error("I found an error :(."); | ||
console.error( | ||
"Nothing in clipboard. Pass in a JWT as the first argument or copy a JWT to your clipboard" | ||
); | ||
} | ||
} else if (arg2) { | ||
try { | ||
const decoded = jwtDecode(arg2); | ||
console.log("Decoding: \n" + arg2); | ||
console.log(decoded); | ||
return decoded; | ||
} catch (e) { | ||
console.error("I found an error :(."); | ||
console.error(e, e.message); | ||
throw e; | ||
} | ||
} else { | ||
console.error("I found an error :(."); | ||
console.error( | ||
"Nothing in clipboard and no arguments given. Pass in a JWT as the first argument or copy a JWT to your clipboard" | ||
); | ||
throw new Error( | ||
"Nothing in clipboard and no arguments given. Pass in a JWT as the first argument or copy a JWT to your clipboard" | ||
); | ||
} | ||
return 1; | ||
}; | ||
|
||
// read from clipboard | ||
let clipboard; | ||
try { | ||
clipboard = clipboardy.readSync(); | ||
} catch (e) { | ||
clipboard = null; | ||
} | ||
|
||
// read passed in argument | ||
const argv = process.argv; | ||
|
||
cli(clipboard, argv); | ||
|
||
export default cli; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
|
||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = exports.cli = exports.HELP_TEXT = void 0; | ||
|
||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
|
||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
|
||
var _lib = require("../lib"); | ||
|
||
var _clipboardy = _interopRequireDefault(require("clipboardy")); | ||
|
||
var decode = /*#__PURE__*/function () { | ||
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(jwt) { | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _lib.jwtDecode)(jwt); | ||
|
||
case 2: | ||
return _context.abrupt("return", _context.sent); | ||
|
||
case 3: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
|
||
return function decode(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
|
||
var HELP_TEXT = "******HELP*****\n\ | ||
use -c or --clipboard or call command with no arguments to decode the JWT in your clipboard\n\ | ||
or call command with JWT as first argument\n\ | ||
****************"; | ||
exports.HELP_TEXT = HELP_TEXT; | ||
|
||
var cli = /*#__PURE__*/function () { | ||
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(clipboard, argv) { | ||
var arg2, decoded, _decoded; | ||
|
||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
// read passed in argument | ||
if (argv) { | ||
arg2 = argv[2]; | ||
} | ||
|
||
if (!(arg2 == "-h" || arg2 === "--help")) { | ||
_context2.next = 6; | ||
break; | ||
} | ||
|
||
// Help display | ||
console.log(HELP_TEXT); | ||
return _context2.abrupt("return", HELP_TEXT); | ||
|
||
case 6: | ||
if (!(arg2 === "-c" || arg2 === "--clipboard" || !arg2)) { | ||
_context2.next = 31; | ||
break; | ||
} | ||
|
||
if (!clipboard) { | ||
_context2.next = 27; | ||
break; | ||
} | ||
|
||
_context2.prev = 8; | ||
_context2.next = 11; | ||
return decode(clipboard); | ||
|
||
case 11: | ||
decoded = _context2.sent; | ||
// Show what we found in the clipboard | ||
console.log("Decoding: "); | ||
console.log(clipboard); // Show the decoded jwt. | ||
|
||
console.log(decoded); | ||
return _context2.abrupt("return", decoded); | ||
|
||
case 18: | ||
_context2.prev = 18; | ||
_context2.t0 = _context2["catch"](8); | ||
console.error("I found an error :(."); | ||
console.error("Couldn't decode what was in clipboard. Pass in a JWT as the first argument or copy a JWT to your clipboard"); | ||
console.error("what's on your clipboard? "); | ||
console.error(clipboard); | ||
console.error(_context2.t0, _context2.t0.message); | ||
|
||
case 25: | ||
_context2.next = 29; | ||
break; | ||
|
||
case 27: | ||
console.error("I found an error :(."); | ||
console.error("Nothing in clipboard. Pass in a JWT as the first argument or copy a JWT to your clipboard"); | ||
|
||
case 29: | ||
_context2.next = 47; | ||
break; | ||
|
||
case 31: | ||
if (!arg2) { | ||
_context2.next = 45; | ||
break; | ||
} | ||
|
||
_context2.prev = 32; | ||
_decoded = (0, _lib.jwtDecode)(arg2); | ||
console.log("Decoding: \n" + arg2); | ||
console.log(_decoded); | ||
return _context2.abrupt("return", _decoded); | ||
|
||
case 39: | ||
_context2.prev = 39; | ||
_context2.t1 = _context2["catch"](32); | ||
console.error("I found an error :(."); | ||
console.error(_context2.t1, _context2.t1.message); | ||
|
||
case 43: | ||
_context2.next = 47; | ||
break; | ||
|
||
case 45: | ||
console.error("I found an error :(."); | ||
console.error("Nothing in clipboard and no arguments given. Pass in a JWT as the first argument or copy a JWT to your clipboard"); | ||
|
||
case 47: | ||
return _context2.abrupt("return", 1); | ||
|
||
case 48: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, null, [[8, 18], [32, 39]]); | ||
})); | ||
|
||
return function cli(_x2, _x3) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}(); // read from clipboard | ||
|
||
|
||
exports.cli = cli; | ||
var clipboard; | ||
|
||
try { | ||
clipboard = _clipboardy["default"].readSync(); | ||
} catch (e) { | ||
clipboard = null; | ||
} // read passed in argument | ||
|
||
|
||
var argv = process.argv; | ||
cli(clipboard, argv); | ||
var _default = cli; | ||
exports["default"] = _default; |
Oops, something went wrong.