@sso-id/cli 0.0.0-stage → 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/bin/sso-id.mjs +60 -0
- package/package.json +27 -4
- package/README.md +0 -3
package/bin/sso-id.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
export function decodeJwt(token) {
|
|
4
|
+
const parts = token.split('.');
|
|
5
|
+
if (parts.length < 2) {
|
|
6
|
+
throw new Error('Invalid JWT token format');
|
|
7
|
+
}
|
|
8
|
+
const header = JSON.parse(Buffer.from(parts[0], 'base64url').toString('utf8'));
|
|
9
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
10
|
+
return { header, payload };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function generateEnvTemplate({ domain, clientId, redirectUri }) {
|
|
14
|
+
return [
|
|
15
|
+
`SSO_ID_DOMAIN=${domain}`,
|
|
16
|
+
`SSO_ID_CLIENT_ID=${clientId}`,
|
|
17
|
+
`SSO_ID_REDIRECT_URI=${redirectUri || 'http://localhost:3000/callback'}`,
|
|
18
|
+
].join('\n');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function main() {
|
|
22
|
+
const [, , cmd, arg1] = process.argv;
|
|
23
|
+
if (!cmd || cmd === '--help' || cmd === '-h') {
|
|
24
|
+
console.log('Usage: sso-id <command>\n\nCommands:\n init <domain> <clientId> Print .env starter config\n decode-token <jwt> Decode JWT header & payload\n test-discovery <domain> Fetch OIDC discovery metadata');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (cmd === 'init') {
|
|
29
|
+
const domain = arg1 || 'acme.sso.id';
|
|
30
|
+
const clientId = process.argv[4] || 'YOUR_CLIENT_ID';
|
|
31
|
+
console.log(generateEnvTemplate({ domain, clientId }));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (cmd === 'decode-token') {
|
|
36
|
+
if (!arg1) throw new Error('Pass a JWT token: sso-id decode-token <jwt>');
|
|
37
|
+
console.log(JSON.stringify(decodeJwt(arg1), null, 2));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (cmd === 'test-discovery') {
|
|
42
|
+
if (!arg1) throw new Error('Pass a domain: sso-id test-discovery <domain>');
|
|
43
|
+
const base = arg1.startsWith('http') ? arg1.replace(/\/+$/, '') : `https://${arg1.replace(/\/+$/, '')}`;
|
|
44
|
+
const res = await fetch(`${base}/auth/.well-known/openid-configuration`);
|
|
45
|
+
if (!res.ok) throw new Error(`Discovery returned HTTP ${res.status}`);
|
|
46
|
+
console.log(JSON.stringify(await res.json(), null, 2));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error(`Unknown command: ${cmd}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isDirectRun = process.argv[1]?.endsWith('sso-id.mjs');
|
|
54
|
+
if (isDirectRun) {
|
|
55
|
+
main().catch((err) => {
|
|
56
|
+
console.error(err.message);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sso-id/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Official SSO.ID Developer CLI (init, decode-token, test-discovery)",
|
|
6
|
+
"bin": {
|
|
7
|
+
"sso-id": "./bin/sso-id.mjs"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "node --test tests/*.test.mjs"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"sso.id",
|
|
14
|
+
"cli",
|
|
15
|
+
"oidc",
|
|
16
|
+
"jwt",
|
|
17
|
+
"developer-tools"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18.0.0"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin"
|
|
28
|
+
]
|
|
29
|
+
}
|
package/README.md
DELETED