slek-ai-cli 1.1.9 → 1.1.11
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/auth.js +27 -27
- package/package.json +1 -1
package/auth.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const http
|
|
5
|
-
const urlModule
|
|
6
|
-
const path
|
|
7
|
-
const fs
|
|
4
|
+
const http = require('http');
|
|
5
|
+
const urlModule = require('url');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
const fs = require('fs');
|
|
8
8
|
const { execSync } = require('child_process');
|
|
9
|
-
const axios
|
|
10
|
-
const chalk
|
|
11
|
-
const boxen
|
|
9
|
+
const axios = require('axios');
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const boxen = require('boxen');
|
|
12
12
|
|
|
13
13
|
// Load environment variables from .env
|
|
14
14
|
require('dotenv').config({ path: path.join(__dirname, '.env') });
|
|
15
15
|
|
|
16
16
|
// ─── Firebase / Google config ────────────────────────────────────────────────
|
|
17
|
-
const FIREBASE_API_KEY
|
|
17
|
+
const FIREBASE_API_KEY = process.env.FIREBASE_API_KEY || 'AIzaSyBoQHn_adTTj1ZaYZBMHCMSAblCGCIbQG4';
|
|
18
18
|
const FIREBASE_AUTH_DOMAIN = process.env.FIREBASE_AUTH_DOMAIN || 'charm-f004f.firebaseapp.com';
|
|
19
19
|
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID || '763614479011-v2m44ees6jhjaprj5ndoa0up83gf1qah.apps.googleusercontent.com';
|
|
20
20
|
const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET || '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';
|
|
21
21
|
|
|
22
22
|
const REDIRECT_URI = 'http://localhost:9876/callback';
|
|
23
|
-
const AUTH_PORT
|
|
23
|
+
const AUTH_PORT = 9876;
|
|
24
24
|
|
|
25
25
|
// ─── Token storage (saved in user home directory) ─────────────────────────────
|
|
26
26
|
const TOKEN_PATH = path.join(
|
|
@@ -38,12 +38,12 @@ function loadToken() {
|
|
|
38
38
|
if (fs.existsSync(TOKEN_PATH)) {
|
|
39
39
|
return JSON.parse(fs.readFileSync(TOKEN_PATH, 'utf8'));
|
|
40
40
|
}
|
|
41
|
-
} catch (_) {}
|
|
41
|
+
} catch (_) { }
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
function clearToken() {
|
|
46
|
-
try { fs.unlinkSync(TOKEN_PATH); } catch (_) {}
|
|
46
|
+
try { fs.unlinkSync(TOKEN_PATH); } catch (_) { }
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
function isLoggedIn() {
|
|
@@ -78,12 +78,12 @@ function openBrowser(targetUrl) {
|
|
|
78
78
|
// ─── Google OAuth URL ────────────────────────────────────────────────────────
|
|
79
79
|
function buildGoogleAuthUrl() {
|
|
80
80
|
const authUrl = new URL('https://accounts.google.com/o/oauth2/v2/auth');
|
|
81
|
-
authUrl.searchParams.set('client_id',
|
|
82
|
-
authUrl.searchParams.set('redirect_uri',
|
|
81
|
+
authUrl.searchParams.set('client_id', GOOGLE_CLIENT_ID);
|
|
82
|
+
authUrl.searchParams.set('redirect_uri', REDIRECT_URI);
|
|
83
83
|
authUrl.searchParams.set('response_type', 'code');
|
|
84
|
-
authUrl.searchParams.set('scope',
|
|
85
|
-
authUrl.searchParams.set('access_type',
|
|
86
|
-
authUrl.searchParams.set('prompt',
|
|
84
|
+
authUrl.searchParams.set('scope', 'openid email profile');
|
|
85
|
+
authUrl.searchParams.set('access_type', 'offline');
|
|
86
|
+
authUrl.searchParams.set('prompt', 'select_account');
|
|
87
87
|
return authUrl.toString();
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -91,10 +91,10 @@ function buildGoogleAuthUrl() {
|
|
|
91
91
|
async function exchangeCodeForToken(code) {
|
|
92
92
|
const tokenRes = await axios.post('https://oauth2.googleapis.com/token', {
|
|
93
93
|
code,
|
|
94
|
-
client_id:
|
|
94
|
+
client_id: GOOGLE_CLIENT_ID,
|
|
95
95
|
client_secret: GOOGLE_CLIENT_SECRET,
|
|
96
|
-
redirect_uri:
|
|
97
|
-
grant_type:
|
|
96
|
+
redirect_uri: REDIRECT_URI,
|
|
97
|
+
grant_type: 'authorization_code',
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
const { id_token } = tokenRes.data;
|
|
@@ -102,18 +102,18 @@ async function exchangeCodeForToken(code) {
|
|
|
102
102
|
const firebaseRes = await axios.post(
|
|
103
103
|
`https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=${FIREBASE_API_KEY}`,
|
|
104
104
|
{
|
|
105
|
-
postBody:
|
|
106
|
-
requestUri:
|
|
105
|
+
postBody: `id_token=${id_token}&providerId=google.com`,
|
|
106
|
+
requestUri: REDIRECT_URI,
|
|
107
107
|
returnIdpCredential: true,
|
|
108
|
-
returnSecureToken:
|
|
108
|
+
returnSecureToken: true,
|
|
109
109
|
}
|
|
110
110
|
);
|
|
111
111
|
|
|
112
112
|
const { displayName, email, idToken, expiresIn, photoUrl } = firebaseRes.data;
|
|
113
113
|
return {
|
|
114
|
-
name:
|
|
114
|
+
name: displayName,
|
|
115
115
|
email,
|
|
116
|
-
photo:
|
|
116
|
+
photo: photoUrl || '',
|
|
117
117
|
idToken,
|
|
118
118
|
expiresAt: Date.now() + parseInt(expiresIn) * 1000,
|
|
119
119
|
};
|
|
@@ -163,7 +163,7 @@ async function login() {
|
|
|
163
163
|
|
|
164
164
|
server.close();
|
|
165
165
|
|
|
166
|
-
const code
|
|
166
|
+
const code = parsed.query.code;
|
|
167
167
|
const error = parsed.query.error;
|
|
168
168
|
if (error) {
|
|
169
169
|
console.log(chalk.red('\n ✗ Login cancelled.\n'));
|
|
@@ -179,7 +179,7 @@ async function login() {
|
|
|
179
179
|
console.log(
|
|
180
180
|
'\n' + boxen(
|
|
181
181
|
chalk.green('✓ Logged in successfully!\n\n') +
|
|
182
|
-
chalk.cyan('Name : ') + chalk.white(userData.name)
|
|
182
|
+
chalk.cyan('Name : ') + chalk.white(userData.name) + '\n' +
|
|
183
183
|
chalk.cyan('Email : ') + chalk.white(userData.email),
|
|
184
184
|
{ padding: 1, margin: { left: 2 }, borderStyle: 'round', borderColor: 'green' }
|
|
185
185
|
)
|
|
@@ -242,7 +242,7 @@ function status() {
|
|
|
242
242
|
console.log(
|
|
243
243
|
'\n' + boxen(
|
|
244
244
|
chalk.green('✓ Logged in\n\n') +
|
|
245
|
-
chalk.cyan('Name : ') + chalk.white(user.name)
|
|
245
|
+
chalk.cyan('Name : ') + chalk.white(user.name) + '\n' +
|
|
246
246
|
chalk.cyan('Email : ') + chalk.white(user.email),
|
|
247
247
|
{ padding: 1, margin: { left: 2 }, borderStyle: 'round', borderColor: 'green' }
|
|
248
248
|
) + '\n'
|