-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
38 lines (35 loc) · 1.26 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
#!/usr/bin/env node
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers';
import clientAssertion from './lib/commands/client-assertion.js';
import signJWT from './lib/commands/sign-jwt.js';
import fs from 'fs';
const packageJson = JSON.parse(fs.readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
const argv = yargs(hideBin(process.argv))
.version(packageJson.version)
.command('client-assertion', 'Create a signed JWT to use as the client assertion for the OAuth token post')
.demandCommand(1)
.option('client-id', {
demandOption: true,
describe: 'client id to use for the OAuth token flow',
type: 'string'
})
.option('private-key', {
demandOption: true,
describe: 'Path to the PEM encoded private key used to sign the assertion',
type: 'string'
})
.command('sign-jwt', 'Only create a signed JWT for use with the Banno back office OAuth flow')
.strict()
.help()
.argv;
switch (argv._[0].toString().toLowerCase()) {
case 'client-assertion':
clientAssertion(argv['client-id'], argv['private-key']).catch((e) => console.error(e));
break;
case 'sign-jwt':
signJWT(argv['client-id'], argv['private-key']).catch((e) => console.error(e));
break;
default:
break;
}