hanka-cli 0.1.1 → 0.1.2
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/index.js +8 -8
- package/package.json +1 -1
- package/src/index.ts +11 -8
package/dist/index.js
CHANGED
|
@@ -20,11 +20,15 @@ program
|
|
|
20
20
|
const spinner = ora('Requesting device code...').start();
|
|
21
21
|
const deviceRes = await fetch('https://github.com/login/device/code', {
|
|
22
22
|
method: 'POST',
|
|
23
|
-
headers: { 'Content-Type': 'application/
|
|
24
|
-
body:
|
|
23
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
24
|
+
body: `client_id=${GITHUB_CLIENT_ID}&scope=repo`,
|
|
25
25
|
});
|
|
26
26
|
const deviceData = await deviceRes.json();
|
|
27
27
|
spinner.stop();
|
|
28
|
+
if (deviceData.error) {
|
|
29
|
+
console.error(chalk.red(`GitHub error: ${deviceData.error_description ?? deviceData.error}`));
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
28
32
|
console.log();
|
|
29
33
|
console.log(chalk.bold('Open this URL in your browser:'));
|
|
30
34
|
console.log(chalk.cyan(' ' + deviceData.verification_uri));
|
|
@@ -38,12 +42,8 @@ program
|
|
|
38
42
|
await new Promise(r => setTimeout(r, (deviceData.interval + 1) * 1000));
|
|
39
43
|
const pollRes = await fetch('https://github.com/login/oauth/access_token', {
|
|
40
44
|
method: 'POST',
|
|
41
|
-
headers: { 'Content-Type': 'application/
|
|
42
|
-
body:
|
|
43
|
-
client_id: GITHUB_CLIENT_ID,
|
|
44
|
-
device_code: deviceData.device_code,
|
|
45
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
46
|
-
}),
|
|
45
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
46
|
+
body: `client_id=${GITHUB_CLIENT_ID}&device_code=${deviceData.device_code}&grant_type=urn:ietf:params:oauth:grant-type:device_code`,
|
|
47
47
|
});
|
|
48
48
|
const pollData = await pollRes.json();
|
|
49
49
|
if (pollData.access_token) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -25,8 +25,8 @@ program
|
|
|
25
25
|
|
|
26
26
|
const deviceRes = await fetch('https://github.com/login/device/code', {
|
|
27
27
|
method: 'POST',
|
|
28
|
-
headers: { 'Content-Type': 'application/
|
|
29
|
-
body:
|
|
28
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
29
|
+
body: `client_id=${GITHUB_CLIENT_ID}&scope=repo`,
|
|
30
30
|
})
|
|
31
31
|
const deviceData = await deviceRes.json() as {
|
|
32
32
|
device_code: string
|
|
@@ -34,9 +34,16 @@ program
|
|
|
34
34
|
verification_uri: string
|
|
35
35
|
interval: number
|
|
36
36
|
expires_in: number
|
|
37
|
+
error?: string
|
|
38
|
+
error_description?: string
|
|
37
39
|
}
|
|
38
40
|
spinner.stop()
|
|
39
41
|
|
|
42
|
+
if (deviceData.error) {
|
|
43
|
+
console.error(chalk.red(`GitHub error: ${deviceData.error_description ?? deviceData.error}`))
|
|
44
|
+
process.exit(1)
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
console.log()
|
|
41
48
|
console.log(chalk.bold('Open this URL in your browser:'))
|
|
42
49
|
console.log(chalk.cyan(' ' + deviceData.verification_uri))
|
|
@@ -53,12 +60,8 @@ program
|
|
|
53
60
|
|
|
54
61
|
const pollRes = await fetch('https://github.com/login/oauth/access_token', {
|
|
55
62
|
method: 'POST',
|
|
56
|
-
headers: { 'Content-Type': 'application/
|
|
57
|
-
body:
|
|
58
|
-
client_id: GITHUB_CLIENT_ID,
|
|
59
|
-
device_code: deviceData.device_code,
|
|
60
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
61
|
-
}),
|
|
63
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
64
|
+
body: `client_id=${GITHUB_CLIENT_ID}&device_code=${deviceData.device_code}&grant_type=urn:ietf:params:oauth:grant-type:device_code`,
|
|
62
65
|
})
|
|
63
66
|
const pollData = await pollRes.json() as { access_token?: string; error?: string }
|
|
64
67
|
|