@circleback/cli 0.1.8 → 0.1.9
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/dist/auth/oauth.js +2 -1
- package/dist/commands/auth.js +28 -2
- package/package.json +1 -1
package/dist/auth/oauth.js
CHANGED
|
@@ -90,7 +90,7 @@ const refreshAccessToken = async (refreshToken, clientId) => {
|
|
|
90
90
|
return tokenData;
|
|
91
91
|
};
|
|
92
92
|
exports.refreshAccessToken = refreshAccessToken;
|
|
93
|
-
const login = async () => {
|
|
93
|
+
const login = async (options = {}) => {
|
|
94
94
|
const { port, waitForCallback, shutdown } = await (0, server_1.startCallbackServer)();
|
|
95
95
|
const redirectUri = `http://127.0.0.1:${port}`;
|
|
96
96
|
try {
|
|
@@ -106,6 +106,7 @@ const login = async () => {
|
|
|
106
106
|
authorizeUrl.searchParams.set('code_challenge', challenge);
|
|
107
107
|
authorizeUrl.searchParams.set('code_challenge_method', 'S256');
|
|
108
108
|
const url = authorizeUrl.toString();
|
|
109
|
+
options.onAuthorizeUrl?.(url);
|
|
109
110
|
const isWindows = process.platform === 'win32';
|
|
110
111
|
const escapedUrl = isWindows ? url.replace(/&/g, '^&') : url;
|
|
111
112
|
const [command, ...arguments_] = isWindows
|
package/dist/commands/auth.js
CHANGED
|
@@ -8,6 +8,24 @@ const commander_1 = require("commander");
|
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const oauth_1 = require("../auth/oauth");
|
|
10
10
|
const tokenStorage_1 = require("../auth/tokenStorage");
|
|
11
|
+
const AUTHORIZATION_URL_FALLBACK_DELAY_MILLISECONDS = 500;
|
|
12
|
+
const getOpenUrlInstruction = () => process.platform === 'darwin' ? '⌘-click' : 'Ctrl-click';
|
|
13
|
+
const createAuthorizationUrlFallback = () => {
|
|
14
|
+
const abortController = new AbortController();
|
|
15
|
+
const schedule = (url) => {
|
|
16
|
+
const timeout = setTimeout(() => {
|
|
17
|
+
if (abortController.signal.aborted)
|
|
18
|
+
return;
|
|
19
|
+
console.log(`Browser didn't open? ${getOpenUrlInstruction()} the URL below to log in.\n`);
|
|
20
|
+
console.log(chalk_1.default.cyan(url));
|
|
21
|
+
}, AUTHORIZATION_URL_FALLBACK_DELAY_MILLISECONDS);
|
|
22
|
+
abortController.signal.addEventListener('abort', () => clearTimeout(timeout), { once: true });
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
schedule,
|
|
26
|
+
cleanup: () => abortController.abort(),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
11
29
|
exports.loginCommand = new commander_1.Command('login')
|
|
12
30
|
.description('Authenticate with Circleback via browser.')
|
|
13
31
|
.action(async () => {
|
|
@@ -17,8 +35,16 @@ exports.loginCommand = new commander_1.Command('login')
|
|
|
17
35
|
console.log(chalk_1.default.yellow('Already authenticated. Run `circleback logout` first to re-authenticate.'));
|
|
18
36
|
return;
|
|
19
37
|
}
|
|
20
|
-
console.log('Opening browser for authentication
|
|
21
|
-
|
|
38
|
+
console.log('Opening your browser for authentication…\n');
|
|
39
|
+
const authorizationUrlFallback = createAuthorizationUrlFallback();
|
|
40
|
+
try {
|
|
41
|
+
await (0, oauth_1.login)({
|
|
42
|
+
onAuthorizeUrl: authorizationUrlFallback.schedule,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
authorizationUrlFallback.cleanup();
|
|
47
|
+
}
|
|
22
48
|
console.log(chalk_1.default.green('Authentication successful.'));
|
|
23
49
|
}
|
|
24
50
|
catch (error) {
|
package/package.json
CHANGED