learn-auth-sdk 0.2.3 → 0.2.4
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 +6 -34
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -239,48 +239,20 @@ Log in on ${baseUrl}`);
|
|
|
239
239
|
if (!deviceAuthorized) {
|
|
240
240
|
throw new Error("Device authorization timeout");
|
|
241
241
|
}
|
|
242
|
-
console.log("\n\nDevice authorized!
|
|
243
|
-
const
|
|
242
|
+
console.log("\n\nDevice authorized! Retrieving access token...");
|
|
243
|
+
const finalTokenResponse = await fetch(`${baseUrl}/api/auth/cli/token`, {
|
|
244
244
|
method: "POST",
|
|
245
245
|
headers: {
|
|
246
246
|
"Content-Type": "application/json"
|
|
247
247
|
},
|
|
248
248
|
body: JSON.stringify({
|
|
249
|
-
device_code: deviceData.device_code
|
|
250
|
-
sdk_name: SDK_NAME,
|
|
251
|
-
machine_id: machineInfo.machineId
|
|
249
|
+
device_code: deviceData.device_code
|
|
252
250
|
})
|
|
253
251
|
});
|
|
254
|
-
if (!
|
|
255
|
-
|
|
256
|
-
throw new Error(errorData.message || "Failed to send 2FA code");
|
|
252
|
+
if (!finalTokenResponse.ok) {
|
|
253
|
+
throw new Error("Failed to retrieve access token");
|
|
257
254
|
}
|
|
258
|
-
|
|
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();
|
|
255
|
+
const tokenData = await finalTokenResponse.json();
|
|
284
256
|
writeSDKCredentials(SDK_NAME, {
|
|
285
257
|
access_token: tokenData.access_token,
|
|
286
258
|
refresh_token: null,
|