@sso-id/cli 0.2.0 → 0.2.1
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 +45 -2
- package/package.json +1 -1
package/bin/sso-id.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
2
3
|
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { dirname, join, resolve } from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
@@ -62,6 +63,7 @@ export function parseFlags(argv) {
|
|
|
62
63
|
|
|
63
64
|
export function applyEnvOverrides(templateEnv, overrides) {
|
|
64
65
|
let content = templateEnv;
|
|
66
|
+
const sessionSecret = overrides.sessionSecret || randomBytes(32).toString('hex');
|
|
65
67
|
const replacements = {
|
|
66
68
|
SSO_ID_DOMAIN: overrides.domain,
|
|
67
69
|
NEXT_PUBLIC_SSO_ID_DOMAIN: overrides.domain,
|
|
@@ -70,9 +72,16 @@ export function applyEnvOverrides(templateEnv, overrides) {
|
|
|
70
72
|
NEXT_PUBLIC_SSO_ID_CLIENT_ID: overrides.clientId,
|
|
71
73
|
VITE_SSO_ID_CLIENT_ID: overrides.clientId,
|
|
72
74
|
SSO_ID_CLIENT_SECRET: overrides.clientSecret,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
SSO_ID_REDIRECT_URI: overrides.redirectUri,
|
|
76
|
+
NEXT_PUBLIC_SSO_ID_REDIRECT_URI: overrides.redirectUri,
|
|
77
|
+
VITE_SSO_ID_REDIRECT_URI: overrides.redirectUri,
|
|
78
|
+
SSO_ID_M2M_CLIENT_ID: overrides.m2mClientId || overrides.clientId,
|
|
79
|
+
SSO_ID_M2M_CLIENT_SECRET: overrides.m2mClientSecret || overrides.clientSecret,
|
|
80
|
+
SSO_ID_API_BASE_URL: overrides.apiBaseUrl,
|
|
81
|
+
SSO_ID_AUDIENCE: overrides.audience,
|
|
82
|
+
SSO_ID_SESSION_SECRET: sessionSecret,
|
|
75
83
|
SSO_ID_SCIM_BEARER_TOKEN: overrides.scimToken,
|
|
84
|
+
SSO_ID_SCIM_CONNECTION_ID: overrides.scimConnectionId,
|
|
76
85
|
};
|
|
77
86
|
for (const [key, val] of Object.entries(replacements)) {
|
|
78
87
|
if (!val) continue;
|
|
@@ -86,6 +95,32 @@ export function applyEnvOverrides(templateEnv, overrides) {
|
|
|
86
95
|
return `${content.trimEnd()}\n`;
|
|
87
96
|
}
|
|
88
97
|
|
|
98
|
+
function patchStructuredConfigs(destDir, overrides) {
|
|
99
|
+
const angularEnvPath = join(destDir, 'src', 'environments', 'environment.ts');
|
|
100
|
+
if (existsSync(angularEnvPath)) {
|
|
101
|
+
let ngEnv = readFileSync(angularEnvPath, 'utf8');
|
|
102
|
+
if (overrides.domain) ngEnv = ngEnv.replace(/ssoIdDomain:\s*'[^']*'/, `ssoIdDomain: '${overrides.domain}'`);
|
|
103
|
+
if (overrides.clientId) ngEnv = ngEnv.replace(/ssoIdClientId:\s*'[^']*'/, `ssoIdClientId: '${overrides.clientId}'`);
|
|
104
|
+
if (overrides.redirectUri) ngEnv = ngEnv.replace(/ssoIdRedirectUri:\s*'[^']*'/, `ssoIdRedirectUri: '${overrides.redirectUri}'`);
|
|
105
|
+
writeFileSync(angularEnvPath, ngEnv, 'utf8');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const appsettingsPath = join(destDir, 'appsettings.json');
|
|
109
|
+
if (existsSync(appsettingsPath)) {
|
|
110
|
+
const cfg = JSON.parse(readFileSync(appsettingsPath, 'utf8'));
|
|
111
|
+
cfg.SsoId = cfg.SsoId || {};
|
|
112
|
+
cfg.Scim = cfg.Scim || {};
|
|
113
|
+
if (overrides.domain) cfg.SsoId.Domain = overrides.domain;
|
|
114
|
+
if (overrides.m2mClientId || overrides.clientId) cfg.SsoId.ClientId = overrides.m2mClientId || overrides.clientId;
|
|
115
|
+
if (overrides.m2mClientSecret || overrides.clientSecret) cfg.SsoId.ClientSecret = overrides.m2mClientSecret || overrides.clientSecret;
|
|
116
|
+
if (overrides.apiBaseUrl) cfg.SsoId.ApiBaseUrl = overrides.apiBaseUrl;
|
|
117
|
+
if (overrides.audience) cfg.SsoId.Audience = overrides.audience;
|
|
118
|
+
if (overrides.scimToken) cfg.Scim.BearerToken = overrides.scimToken;
|
|
119
|
+
if (overrides.scimConnectionId) cfg.Scim.ConnectionId = overrides.scimConnectionId;
|
|
120
|
+
writeFileSync(appsettingsPath, `${JSON.stringify(cfg, null, 2)}\n`, 'utf8');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
89
124
|
export function scaffoldTemplate(templateName, targetDir, overrides = {}) {
|
|
90
125
|
if (!AVAILABLE_TEMPLATES.includes(templateName)) {
|
|
91
126
|
throw new Error(`Unknown template "${templateName}". Available: ${AVAILABLE_TEMPLATES.join(', ')}`);
|
|
@@ -104,6 +139,7 @@ export function scaffoldTemplate(templateName, targetDir, overrides = {}) {
|
|
|
104
139
|
? readFileSync(envExamplePath, 'utf8')
|
|
105
140
|
: generateEnvTemplate({ domain: 'acme.sso.id', clientId: 'YOUR_CLIENT_ID', ...overrides });
|
|
106
141
|
writeFileSync(join(destDir, '.env'), applyEnvOverrides(baseEnv, overrides), 'utf8');
|
|
142
|
+
patchStructuredConfigs(destDir, overrides);
|
|
107
143
|
} else {
|
|
108
144
|
writeFileSync(
|
|
109
145
|
join(destDir, '.env'),
|
|
@@ -141,7 +177,14 @@ async function main() {
|
|
|
141
177
|
domain: flags.domain,
|
|
142
178
|
clientId: flags['client-id'],
|
|
143
179
|
clientSecret: flags['client-secret'],
|
|
180
|
+
m2mClientId: flags['m2m-client-id'],
|
|
181
|
+
m2mClientSecret: flags['m2m-client-secret'],
|
|
182
|
+
redirectUri: flags['redirect-uri'],
|
|
183
|
+
apiBaseUrl: flags['api-base-url'],
|
|
184
|
+
sessionSecret: flags['session-secret'],
|
|
185
|
+
audience: flags.audience,
|
|
144
186
|
scimToken: flags['scim-token'],
|
|
187
|
+
scimConnectionId: flags['scim-connection-id'],
|
|
145
188
|
});
|
|
146
189
|
console.log(`Created SSO.ID "${arg1}" starter at: ${dest}`);
|
|
147
190
|
return;
|