@snyk/jwt-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # jwt-cli
2
+ A simple CLI tool to create signed JWTs with some asymetric key generation thrown in for fun.
3
+
4
+ Using this tool you can quickly create RSA256 key pairs, mint a JWT and have your public key available in either PEM or JWKS format.
5
+
6
+ Your other alternative is to run a full authentication and gateway stack when developing locally - so this should save you some headaches.
7
+
8
+ **ATTENTION PLEASE:** This tool is designed to help you with local development only - it is probably not safe for generating production keys.
9
+
10
+ ## Build
11
+
12
+ ```shell
13
+ $ make build
14
+ ```
15
+
16
+ ## Create a JWT
17
+ To create a token, first you're going to need some keys:
18
+
19
+ ```shell
20
+ $ ./bin/jwt keys
21
+ writing jwt_private_key.pem ...
22
+ writing jwt_public_key.pem ...
23
+ writing jwt_jwks.json ...
24
+ ```
25
+
26
+ This wll output your private and public keys as PEM files.
27
+
28
+ It will also output your public key in JWK format in case you need to copy that somewhere.
29
+
30
+ Once you have some keys, you can create a token:
31
+
32
+ ```shell
33
+ $ ./bin/jwt create
34
+ eyJhbGciOiJSUzI1NiIsImtpZCI6Imp3dC1jbGkta2V5IiwidHlwIjoiSldUIn0.eyJhdWQiOiJodHRwOi8vbG9jYWxob3N0IiwiYXpwIjoiMWVmZmJlZTUtZGY4ZS00YWU4LTlhNGQtOTJlNGYwMWE4YjQ0IiwiZW50cyI6IiIsImV4cCI6MTY0NjU3OTE1MCwiaWF0IjoxNjQ2NTc5MDkwLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0IiwicHR5cGUiOiJ1c2VyIiwic3ViIjoiZDExMDhiNmYtODM0OS00ZWQxLWI1ZTgtYWY0OTM4OWNiNWQwIn0.RfN5o30tVC-oNnoj5uDDH27TcUxSOFBXLwsd6hqJeYqm4AheV4F4OT5O9CbpK7V9WV3C41i5iN1L5WNjEOR2xtHxVb-nOmKWlwIN2_0B9s03A0FhSbeNKcKKU5K6umLL9f-H03X778i5LoArlOCrOBp6zywK8K8LIuDdGY8erY5ITs_1z8ABafakpZGlAvD2OuJdZX56zTRh_7yJ6lBGVeFWNgIoBK2QlEutVv4o9rWZUIZqsnte1SBu4tXXuk3ykSNrX4p2nFAP08Z-hg78C8ExBrAK7udxo0hdj7Dy27LF8YN0UzD7FD7dbGUyb9AMZk1Iy_lEhMUEQGHAUezq8Q
35
+ ```
36
+
37
+ ## Validate your JWT
38
+ Create some keys and a token then head over to [jwt.io](https://jwt.io).
39
+
40
+ Copy in your token then either copy in the contents of your public key PEM file or your JWK.
41
+
42
+ Note that the signature should show as valid.
43
+
44
+ ## Command reference
45
+ You can get help with commands by using the in built help function, alternatively checkout below
46
+
47
+ ### Keys
48
+ ```shell
49
+ ./bin/jwt help keys
50
+ NAME:
51
+ jwt keys - create signing keys
52
+
53
+ USAGE:
54
+ jwt keys [command options] [arguments...]
55
+
56
+ OPTIONS:
57
+ --out value, -o value relative path to write keys to
58
+ ```
59
+
60
+ Example of changing the output path for files:
61
+ ```shell
62
+ ./bin/jwt keys --out some/other/path
63
+ ```
64
+
65
+ ### Create
66
+ ```shell
67
+ .bin/jwt help create
68
+ NAME:
69
+ jwt create - create a jwt
70
+
71
+ USAGE:
72
+ jwt create [command options] [arguments...]
73
+
74
+ OPTIONS:
75
+ --pem value relative path to the PEM file for the private key
76
+ --claims value relative path to a JSON file containing claims
77
+ ```
78
+
79
+ You can change the signing PEM with the following:
80
+ ```shell
81
+ ./bin/jwt create --pem some/other/path/private.pem
82
+ ```
83
+
84
+ You can change the claims in the JWT by creating a claims JSON file:
85
+ ```json
86
+ {
87
+ "iss": "http://localhost",
88
+ "aud": "http://localhost",
89
+ "sub": "85b14cf2-af5e-4fc7-9821-453605446f01",
90
+ "azp": "2459210b-dd78-43ae-b0af-b8bad46f8b17",
91
+ "ptype": "user"
92
+ }
93
+ ```
94
+
95
+ Once you have your claims in a json file, simply use the `--claims` flag to target it:
96
+ ```shell
97
+ ./bin/jwt create -claims jwt-claims.json
98
+ ```
99
+
100
+
101
+
package/bin/jwt ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ var path = require('path');
3
+
4
+ // os and arch restrictions are handled by the package.json
5
+ var os = process.platform;
6
+ var arch = process.arch;
7
+
8
+ // Select the right binary for this platform, then exec it with the original
9
+ // arguments. This is a true exec(3), which will take over the pid, env, and
10
+ // file descriptors.
11
+ var jwtPath = path.join(__dirname, '../bin/jwt-' + os + '-' + arch);
12
+ if (os === 'win32') {
13
+ jwtPath = path.join(__dirname, '../bin/jwt.exe');
14
+ }
15
+
16
+ try {
17
+ var kexec = require('kexec');
18
+ kexec(jwtPath, process.argv.slice(2));
19
+ } catch (err) {
20
+ if (err.code !== 'MODULE_NOT_FOUND') {
21
+ console.error('Could not leverage kexec due to error: ' + err.message);
22
+ }
23
+
24
+ var spawn = require('child_process').spawn;
25
+ var proc = spawn(jwtPath, process.argv.slice(2), { stdio: 'inherit' });
26
+ proc.on('exit', function (code, signal) {
27
+ process.on('exit', function () {
28
+ if (signal) {
29
+ process.kill(process.pid, signal);
30
+ } else {
31
+ process.exit(code);
32
+ }
33
+ });
34
+ });
35
+ }
Binary file
Binary file
Binary file
Binary file
package/bin/jwt.exe ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@snyk/jwt-cli",
3
+ "version": "v0.1.0",
4
+ "description": "jwt-cli is a little command line tool to create jwts locally",
5
+ "bin": {
6
+ "jwt": "bin/jwt"
7
+ },
8
+ "os": [
9
+ "darwin",
10
+ "linux",
11
+ "win32"
12
+ ],
13
+ "cpu": [
14
+ "x64",
15
+ "arm64"
16
+ ],
17
+ "engines": {
18
+ "node": ">=4.4.0"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/snyk/jwt-cli.git"
23
+ },
24
+ "author": "Jack Schofield <jack.schofield@snyk.io>",
25
+ "contributors": [],
26
+ "dependencies": {},
27
+ "devDependencies": {},
28
+ "optionalDependencies": {
29
+ "@jcoreio/kexec": "^4.0.0"
30
+ }
31
+ }