securenow 7.3.0 → 7.4.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/cli/auth.js +14 -2
- package/package.json +1 -1
package/cli/auth.js
CHANGED
|
@@ -19,6 +19,18 @@ function openBrowser(url) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
function buildCliAuthUrl(appUrl, port, nonce, extra = {}) {
|
|
23
|
+
const url = new URL('/cli/auth', appUrl);
|
|
24
|
+
url.searchParams.set('callback', `http://127.0.0.1:${port}/callback`);
|
|
25
|
+
url.searchParams.set('state', nonce);
|
|
26
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
27
|
+
if (value !== undefined && value !== null) {
|
|
28
|
+
url.searchParams.set(key, String(value));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return url.toString();
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
function decodeJwtPayload(token) {
|
|
23
35
|
try {
|
|
24
36
|
const parts = token.split('.');
|
|
@@ -98,7 +110,7 @@ async function loginWithBrowser() {
|
|
|
98
110
|
const email = payload?.email || 'unknown account';
|
|
99
111
|
const safeEmail = email.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
100
112
|
const port = server.address().port;
|
|
101
|
-
const switchUrl =
|
|
113
|
+
const switchUrl = buildCliAuthUrl(appUrl, port, nonce, { force_login: 1 });
|
|
102
114
|
|
|
103
115
|
res.end([
|
|
104
116
|
'<!DOCTYPE html><html><head><meta charset="utf-8"><title>SecureNow CLI Login</title></head>',
|
|
@@ -171,7 +183,7 @@ async function loginWithBrowser() {
|
|
|
171
183
|
|
|
172
184
|
server.listen(0, '127.0.0.1', () => {
|
|
173
185
|
const port = server.address().port;
|
|
174
|
-
const authUrl =
|
|
186
|
+
const authUrl = buildCliAuthUrl(appUrl, port, nonce);
|
|
175
187
|
|
|
176
188
|
console.log('');
|
|
177
189
|
ui.info('Opening browser for authentication...');
|
package/package.json
CHANGED