learn-auth-sdk 0.2.4 → 0.2.6
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 +3 -16
- 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,27 +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
242
|
console.log("\n\nDevice authorized! Retrieving access token...");
|
|
243
|
-
const finalTokenResponse = await fetch(`${baseUrl}/api/auth/cli/token`, {
|
|
244
|
-
method: "POST",
|
|
245
|
-
headers: {
|
|
246
|
-
"Content-Type": "application/json"
|
|
247
|
-
},
|
|
248
|
-
body: JSON.stringify({
|
|
249
|
-
device_code: deviceData.device_code
|
|
250
|
-
})
|
|
251
|
-
});
|
|
252
|
-
if (!finalTokenResponse.ok) {
|
|
253
|
-
throw new Error("Failed to retrieve access token");
|
|
254
|
-
}
|
|
255
|
-
const tokenData = await finalTokenResponse.json();
|
|
256
243
|
writeSDKCredentials(SDK_NAME, {
|
|
257
244
|
access_token: tokenData.access_token,
|
|
258
245
|
refresh_token: null,
|