learn-auth-sdk 0.2.3 → 0.2.5
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/cli/index.js +4 -45
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -211,7 +211,7 @@ Log in on ${baseUrl}`);
|
|
|
211
211
|
});
|
|
212
212
|
console.log("Opening browser...\n");
|
|
213
213
|
await openBrowser(deviceData.verification_uri_complete);
|
|
214
|
-
let
|
|
214
|
+
let tokenData = null;
|
|
215
215
|
const interval = deviceData.interval * 1e3;
|
|
216
216
|
const maxAttempts = Math.ceil(deviceData.expires_in / deviceData.interval);
|
|
217
217
|
let attempts = 0;
|
|
@@ -232,55 +232,14 @@ Log in on ${baseUrl}`);
|
|
|
232
232
|
continue;
|
|
233
233
|
}
|
|
234
234
|
if (tokenResponse.ok) {
|
|
235
|
-
|
|
235
|
+
tokenData = await tokenResponse.json();
|
|
236
236
|
break;
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
if (!
|
|
239
|
+
if (!tokenData) {
|
|
240
240
|
throw new Error("Device authorization timeout");
|
|
241
241
|
}
|
|
242
|
-
console.log("\n\nDevice authorized!
|
|
243
|
-
const tfaResponse = await fetch(`${baseUrl}/api/auth/2fa/send`, {
|
|
244
|
-
method: "POST",
|
|
245
|
-
headers: {
|
|
246
|
-
"Content-Type": "application/json"
|
|
247
|
-
},
|
|
248
|
-
body: JSON.stringify({
|
|
249
|
-
device_code: deviceData.device_code,
|
|
250
|
-
sdk_name: SDK_NAME,
|
|
251
|
-
machine_id: machineInfo.machineId
|
|
252
|
-
})
|
|
253
|
-
});
|
|
254
|
-
if (!tfaResponse.ok) {
|
|
255
|
-
const errorData = await tfaResponse.json().catch(() => ({}));
|
|
256
|
-
throw new Error(errorData.message || "Failed to send 2FA code");
|
|
257
|
-
}
|
|
258
|
-
console.log("2FA code sent to your email.\n");
|
|
259
|
-
const rl2 = readline.createInterface({
|
|
260
|
-
input: process.stdin,
|
|
261
|
-
output: process.stdout
|
|
262
|
-
});
|
|
263
|
-
const tfaCode = await new Promise((resolve) => {
|
|
264
|
-
rl2.question("Enter 2FA code from email: ", (answer) => {
|
|
265
|
-
rl2.close();
|
|
266
|
-
resolve(answer);
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
const verifyResponse = await fetch(`${baseUrl}/api/auth/2fa/verify`, {
|
|
270
|
-
method: "POST",
|
|
271
|
-
headers: {
|
|
272
|
-
"Content-Type": "application/json"
|
|
273
|
-
},
|
|
274
|
-
body: JSON.stringify({
|
|
275
|
-
device_code: deviceData.device_code,
|
|
276
|
-
code: tfaCode.trim()
|
|
277
|
-
})
|
|
278
|
-
});
|
|
279
|
-
if (!verifyResponse.ok) {
|
|
280
|
-
const errorData = await verifyResponse.json().catch(() => ({}));
|
|
281
|
-
throw new Error(errorData.message || "2FA verification failed");
|
|
282
|
-
}
|
|
283
|
-
const tokenData = await verifyResponse.json();
|
|
242
|
+
console.log("\n\nDevice authorized! Retrieving access token...");
|
|
284
243
|
writeSDKCredentials(SDK_NAME, {
|
|
285
244
|
access_token: tokenData.access_token,
|
|
286
245
|
refresh_token: null,
|