@yoonion/mimi-seed-mcp 0.25.2 → 0.25.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/README.md +6 -5
- package/assets/agent-guide.md +29 -5
- package/dist/auth/cli.js +2 -2
- package/dist/auth/constants.d.ts +5 -2
- package/dist/auth/constants.js +17 -10
- package/dist/auth/errors.js +8 -5
- package/dist/auth/google-auth.d.ts +27 -0
- package/dist/auth/google-auth.js +39 -3
- package/dist/core/console-url.d.ts +19 -0
- package/dist/core/console-url.js +61 -0
- package/dist/core/credential-store.js +2 -0
- package/dist/drive/tools.d.ts +0 -1
- package/dist/drive/tools.js +19 -1
- package/dist/i18n/tools-en/android.d.ts +2 -2
- package/dist/i18n/tools-en/android.js +2 -2
- package/dist/i18n/tools-en/jenkins.d.ts +4 -4
- package/dist/i18n/tools-en/jenkins.js +4 -4
- package/dist/instagram/browser-login.js +4 -3
- package/dist/jenkins/credentials.d.ts +7 -3
- package/dist/jenkins/credentials.js +4 -0
- package/dist/jenkins/messages.d.ts +2 -0
- package/dist/jenkins/messages.js +15 -0
- package/dist/lib/human-approval.d.ts +49 -0
- package/dist/lib/human-approval.js +143 -0
- package/dist/lib/package-root.d.ts +5 -0
- package/dist/lib/tool-registrar.d.ts +31 -0
- package/dist/lib/tool-registrar.js +80 -3
- package/dist/registers/android.js +10 -7
- package/dist/registers/auth.js +16 -7
- package/dist/registers/jenkins.js +20 -8
- package/dist/remote-sync.js +13 -4
- package/dist/server.js +2 -1
- package/dist/social/broker-base.d.ts +7 -0
- package/dist/social/broker-base.js +11 -0
- package/dist/social/meta-app-config.d.ts +19 -0
- package/dist/social/meta-app-config.js +83 -0
- package/dist/social/meta-direct-login.d.ts +45 -0
- package/dist/social/meta-direct-login.js +307 -0
- package/dist/social/setup-cli.js +231 -22
- package/dist/threads/browser-login.js +4 -3
- package/npm-shrinkwrap.json +1985 -0
- package/package.json +6 -3
- package/tool-manifest.json +26 -0
package/dist/social/setup-cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { socialBrokerBase } from './broker-base.js';
|
|
2
3
|
// mimi-seed-social-auth — Facebook 페이지 / Instagram 계정 연결.
|
|
3
4
|
//
|
|
4
5
|
// 검증·저장 구현은 facebook/setup.ts · instagram/setup.ts 에 있고, MCP 도구
|
|
@@ -26,6 +27,8 @@ import { connectThreads, refreshThreadsToken } from '../threads/setup.js';
|
|
|
26
27
|
import { connectThreadsInBrowser, ThreadsLoginError } from '../threads/browser-login.js';
|
|
27
28
|
import { resolveLang } from '#core/lang.js';
|
|
28
29
|
import { resolveSocialConfigTarget } from './profile-store.js';
|
|
30
|
+
import { isValidAppId, isValidAppSecret, isValidRedirectUri, isLoopbackRedirect, loadMetaApp, saveMetaApp, } from './meta-app-config.js';
|
|
31
|
+
import { connectWithMetaApp, MetaDirectLoginError } from './meta-direct-login.js';
|
|
29
32
|
// ko 가 원본이고 en 은 `typeof ko` 를 만족해야 한다 — 키를 빠뜨리면 컴파일이 깨진다.
|
|
30
33
|
const ko = {
|
|
31
34
|
title: ' 🤖 Mimi Seed — 소셜 계정 연결 (Facebook / Instagram / Threads)',
|
|
@@ -67,11 +70,49 @@ const ko = {
|
|
|
67
70
|
thNote: ' (Instagram 과 **별개 계정·별개 토큰**. userId 는 토큰에서 자동 조회돼. 수명 약 60일.)',
|
|
68
71
|
thAskToken: ' Threads Access Token: ',
|
|
69
72
|
thAskUserId: ' Threads user ID (선택, 엔터 시 자동 조회): ',
|
|
70
|
-
thExistingAction: ' [Enter/y] 기존 토큰 자동 갱신 [r]
|
|
73
|
+
thExistingAction: ' [Enter/y] 기존 토큰 자동 갱신 [r] 다시 연결 [n] 건너뛰기: ',
|
|
71
74
|
thRefreshing: ' 🔄 기존 Threads 토큰 갱신 중...',
|
|
72
|
-
thRefreshFallback: ' 자동 갱신에 실패했습니다.
|
|
75
|
+
thRefreshFallback: ' 자동 갱신에 실패했습니다. 다시 연결합니다.',
|
|
73
76
|
profile: (id) => ` 소셜 프로필: ${id}`,
|
|
74
|
-
invalidArgs: ' 사용법: mimi-seed-social-auth [facebook|instagram|threads|all] [--profile <id>] [--manual-token]',
|
|
77
|
+
invalidArgs: ' 사용법: mimi-seed-social-auth [facebook|instagram|threads|all] [--profile <id>] [--manual-token] [--reset-app]',
|
|
78
|
+
appHeader: (label) => ` 🔑 내 Meta 앱으로 ${label} 브라우저 로그인 (서버 없음 — 앱 시크릿은 이 컴퓨터에만 저장)`,
|
|
79
|
+
appSaved: (label, id) => ` 저장된 ${label} 앱 사용: ${id} (바꾸려면 --reset-app)`,
|
|
80
|
+
igAppSteps: [
|
|
81
|
+
' 1. developers.facebook.com → 앱 → 사용 사례 "Instagram에서 메시지 및 콘텐츠 관리"',
|
|
82
|
+
' → "Instagram 로그인을 통한 API 설정"',
|
|
83
|
+
' 2. "Instagram 비즈니스 로그인 설정" → OAuth 리디렉션 URI 에 아래 리디렉션 주소를 그대로 등록',
|
|
84
|
+
' 3. 같은 화면의 **Instagram 앱 ID / 앱 시크릿** (Meta 앱 ID 와 다름)',
|
|
85
|
+
' 4. 앱이 개발 모드면: 앱 역할 → Instagram 테스터에 내 계정 추가 → Instagram 앱에서 초대 수락',
|
|
86
|
+
],
|
|
87
|
+
thAppSteps: [
|
|
88
|
+
' 1. developers.facebook.com → 앱 → 사용 사례 "Threads API 액세스" (threads_basic, threads_content_publish)',
|
|
89
|
+
' 2. 사용 사례 설정 → 리디렉션 콜백 URL 에 아래 리디렉션 주소를 그대로 등록',
|
|
90
|
+
' (제거·삭제 콜백 URL 도 채워야 저장됩니다)',
|
|
91
|
+
' 3. 같은 화면의 **Threads 앱 ID / 앱 시크릿**',
|
|
92
|
+
' 4. 앱이 개발 모드면: 앱 역할 → Threads 테스터에 내 계정 추가 → threads.net 설정 → 웹사이트 권한에서 초대 수락',
|
|
93
|
+
],
|
|
94
|
+
redirectSuggest: (uri) => ` 리디렉션 주소 (권장): ${uri}\n (대시보드가 끝에 / 를 붙여 저장하면 그 모양 그대로 입력해야 합니다 — Meta 는 한 글자라도 다르면 거부합니다.)`,
|
|
95
|
+
askAppId: (label) => ` ${label} 앱 ID (엔터: 토큰 직접 입력으로 전환): `,
|
|
96
|
+
askAppSecret: (label) => ` ${label} 앱 시크릿: `,
|
|
97
|
+
askRedirect: (def) => ` 등록한 리디렉션 URI (엔터: ${def}): `,
|
|
98
|
+
badAppId: ' ❌ 앱 ID 는 숫자여야 합니다. 저장하지 않았습니다.',
|
|
99
|
+
badAppSecret: ' ❌ 앱 시크릿 형식이 아닙니다 (영문·숫자 16자 이상). 저장하지 않았습니다.',
|
|
100
|
+
badRedirect: ' ❌ 리디렉션 URI 는 https:// 이거나 포트가 있는 http://localhost 여야 하고, ?·# 를 포함할 수 없습니다.',
|
|
101
|
+
loopbackWait: ' 브라우저에서 로그인·권한 동의를 마치면 자동으로 연결됩니다. 이 터미널을 열어두세요.',
|
|
102
|
+
pasteHow: ' 권한 동의 후 브라우저가 "연결할 수 없음" 같은 페이지로 이동해도 정상입니다.',
|
|
103
|
+
pastePrompt: ' 그 페이지의 주소창 전체 URL 을 붙여 넣으세요: ',
|
|
104
|
+
directFailed: (code) => ` ❌ ${({
|
|
105
|
+
denied: '권한 동의가 취소되었습니다.',
|
|
106
|
+
timeout: '로그인 대기 시간이 지났습니다. 명령을 다시 실행해주세요.',
|
|
107
|
+
state: '붙여 넣은 URL 이 이번 로그인의 리디렉션 주소가 아닙니다 (state·경로 불일치). 다시 실행해주세요.',
|
|
108
|
+
exchange: '인증 코드를 토큰으로 바꾸지 못했습니다. 앱 ID·시크릿·리디렉션 URI 가 앱 대시보드와 정확히 같은지 확인하세요.',
|
|
109
|
+
validation: '받은 토큰으로 계정을 확인하지 못했습니다.',
|
|
110
|
+
configuration: '로그인을 시작하지 못했습니다.',
|
|
111
|
+
}[code] ?? code)} 기존 연결은 보존했습니다.`,
|
|
112
|
+
directReason: (detail) => ` Meta 응답: ${detail}`,
|
|
113
|
+
appLoadFailed: (message) => ` ⚠️ 저장된 앱 설정을 읽지 못했습니다 — 토큰 직접 입력으로 진행합니다.\n ${message}`,
|
|
114
|
+
appSaveFailed: (message) => ` ⚠️ 계정은 연결됐지만 앱 설정은 저장하지 못했습니다. 다음 로그인 때 앱 정보를 다시 묻습니다.\n ${message}`,
|
|
115
|
+
tokenAtAppId: ' 토큰처럼 보입니다 — 토큰 직접 입력으로 전환합니다. (앱 ID 칸에서는 엔터만 누르면 됩니다.)',
|
|
75
116
|
};
|
|
76
117
|
const en = {
|
|
77
118
|
title: ' 🤖 Mimi Seed — Connect social accounts (Facebook / Instagram / Threads)',
|
|
@@ -113,15 +154,83 @@ const en = {
|
|
|
113
154
|
thNote: ' (A **separate account and token** from Instagram. userId is looked up from the token. ~60 days.)',
|
|
114
155
|
thAskToken: ' Threads Access Token: ',
|
|
115
156
|
thAskUserId: ' Threads user ID (optional, Enter to look it up): ',
|
|
116
|
-
thExistingAction: ' [Enter/y] refresh current token [r]
|
|
157
|
+
thExistingAction: ' [Enter/y] refresh current token [r] reconnect [n] skip: ',
|
|
117
158
|
thRefreshing: ' 🔄 Refreshing the existing Threads token...',
|
|
118
|
-
thRefreshFallback: ' Automatic refresh failed. Reconnecting
|
|
159
|
+
thRefreshFallback: ' Automatic refresh failed. Reconnecting.',
|
|
119
160
|
profile: (id) => ` Social profile: ${id}`,
|
|
120
|
-
invalidArgs: ' Usage: mimi-seed-social-auth [facebook|instagram|threads|all] [--profile <id>] [--manual-token]',
|
|
161
|
+
invalidArgs: ' Usage: mimi-seed-social-auth [facebook|instagram|threads|all] [--profile <id>] [--manual-token] [--reset-app]',
|
|
162
|
+
appHeader: (label) => ` 🔑 ${label} browser login with your own Meta app (no server — the app secret stays on this computer)`,
|
|
163
|
+
appSaved: (label, id) => ` Using the saved ${label} app: ${id} (change it with --reset-app)`,
|
|
164
|
+
igAppSteps: [
|
|
165
|
+
' 1. developers.facebook.com → your app → use case "Manage messaging & content on Instagram"',
|
|
166
|
+
' → "API setup with Instagram login"',
|
|
167
|
+
' 2. "Set up Instagram business login" → add the redirect URI below, exactly, to OAuth redirect URIs',
|
|
168
|
+
' 3. The **Instagram app ID / app secret** on that screen (not the Meta app ID)',
|
|
169
|
+
' 4. If the app is in development mode: App roles → add your account as an Instagram Tester → accept in the Instagram app',
|
|
170
|
+
],
|
|
171
|
+
thAppSteps: [
|
|
172
|
+
' 1. developers.facebook.com → your app → use case "Access the Threads API" (threads_basic, threads_content_publish)',
|
|
173
|
+
' 2. Use case settings → add the redirect URI below, exactly, to Redirect Callback URLs',
|
|
174
|
+
' (the Uninstall and Delete callback URLs must be filled in too, or saving fails)',
|
|
175
|
+
' 3. The **Threads app ID / app secret** on that screen',
|
|
176
|
+
' 4. If the app is in development mode: App roles → add your account as a Threads Tester → accept under threads.net Settings → Website permissions',
|
|
177
|
+
],
|
|
178
|
+
redirectSuggest: (uri) => ` Redirect URI (suggested): ${uri}\n (If the dashboard saves it with a trailing /, enter it exactly that way — Meta rejects any difference.)`,
|
|
179
|
+
askAppId: (label) => ` ${label} app ID (Enter: paste a token instead): `,
|
|
180
|
+
askAppSecret: (label) => ` ${label} app secret: `,
|
|
181
|
+
askRedirect: (def) => ` Registered redirect URI (Enter: ${def}): `,
|
|
182
|
+
badAppId: ' ❌ The app ID must be numeric. Nothing was saved.',
|
|
183
|
+
badAppSecret: ' ❌ That is not an app secret (16+ letters and digits). Nothing was saved.',
|
|
184
|
+
badRedirect: ' ❌ The redirect URI must be https:// or http://localhost with a port, without ? or #.',
|
|
185
|
+
loopbackWait: ' Finish login and consent in the browser; the connection completes automatically. Keep this terminal open.',
|
|
186
|
+
pasteHow: ' After consent the browser may show a "site can\'t be reached" page. That is expected.',
|
|
187
|
+
pastePrompt: ' Paste the full URL from that page\'s address bar: ',
|
|
188
|
+
directFailed: (code) => ` ❌ ${({
|
|
189
|
+
denied: 'Consent was cancelled.',
|
|
190
|
+
timeout: 'The login timed out. Run the command again.',
|
|
191
|
+
state: 'The pasted URL is not this login\'s redirect (state or path mismatch). Run the command again.',
|
|
192
|
+
exchange: 'Could not exchange the authorization code. Check that the app ID, secret, and redirect URI match the app dashboard exactly.',
|
|
193
|
+
validation: 'Could not verify the account with the returned token.',
|
|
194
|
+
configuration: 'Could not start the login.',
|
|
195
|
+
}[code] ?? code)} Existing credentials were preserved.`,
|
|
196
|
+
directReason: (detail) => ` Meta said: ${detail}`,
|
|
197
|
+
appLoadFailed: (message) => ` ⚠️ Could not read the saved app settings — continuing with token paste.\n ${message}`,
|
|
198
|
+
appSaveFailed: (message) => ` ⚠️ The account is connected, but the app settings were not saved. You will be asked for the app again next time.\n ${message}`,
|
|
199
|
+
tokenAtAppId: ' That looks like a token — switching to token paste. (At the app ID prompt, just press Enter.)',
|
|
121
200
|
};
|
|
122
201
|
const M = resolveLang() === 'en' ? en : ko;
|
|
123
|
-
|
|
202
|
+
// historySize 0: 입력 기록이 남으면 숨겨 입력한 앱 시크릿이 다음 프롬프트에서 ↑ 키로 그대로 되살아난다.
|
|
203
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, historySize: 0 });
|
|
204
|
+
// readline 이 stdin 을 raw 모드로 잡고 있어 Ctrl-C 가 프로세스에 가지 않는다. 리스너가 없으면 rl 만 닫혀
|
|
205
|
+
// 로그인 대기(로컬 콜백 서버)가 시간 초과까지 살아 있고, 프롬프트에서의 취소가 exit 0 (성공)으로 끝났다.
|
|
206
|
+
rl.on('SIGINT', () => {
|
|
207
|
+
console.log(`\n${M.cancelled}`);
|
|
208
|
+
rl.close();
|
|
209
|
+
process.exit(130);
|
|
210
|
+
});
|
|
124
211
|
const ask = (q) => new Promise((r) => rl.question(q, (a) => r(a.trim())));
|
|
212
|
+
/**
|
|
213
|
+
* 입력을 화면에 찍지 않는 질문 — 앱 시크릿은 만료되지 않고 그 앱을 쓰는 모든 계정의 토큰을 만들 수 있어 터미널
|
|
214
|
+
* 스크롤백·화면 공유에 남으면 안 된다. readline 에는 공개 API 가 없어 출력 함수를 질문 동안만 바꾼다.
|
|
215
|
+
* TTY 가 아니면 찍을 화면도 없으니 그대로 읽는다.
|
|
216
|
+
*/
|
|
217
|
+
const askHidden = (q) => {
|
|
218
|
+
if (!process.stdin.isTTY)
|
|
219
|
+
return ask(q);
|
|
220
|
+
const out = rl;
|
|
221
|
+
const original = out._writeToOutput;
|
|
222
|
+
return new Promise((r) => {
|
|
223
|
+
rl.question(q, (a) => {
|
|
224
|
+
out._writeToOutput = original;
|
|
225
|
+
process.stdout.write('\n');
|
|
226
|
+
r(a.trim());
|
|
227
|
+
});
|
|
228
|
+
// 프롬프트는 이미 찍혔다. 이후 입력 에코만 막는다.
|
|
229
|
+
out._writeToOutput = () => { };
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
/** 앱 ID 칸에 붙여 넣은 토큰 (IGAA… / EAA… / TH… 또는 긴 영숫자) — 예전 사용법 그대로 토큰 입력으로 보낸다. */
|
|
233
|
+
const looksLikeToken = (value) => /^(IGAA|EAA|TH)[A-Za-z0-9]/.test(value) || /^[A-Za-z0-9_-]{40,}$/.test(value);
|
|
125
234
|
async function confirmReconnect(label, detail) {
|
|
126
235
|
console.log(M.already(label, detail));
|
|
127
236
|
const answer = await ask(M.reconnect);
|
|
@@ -171,7 +280,95 @@ async function setupFacebook(profile) {
|
|
|
171
280
|
console.log(M.notSaved);
|
|
172
281
|
return result.ok;
|
|
173
282
|
}
|
|
174
|
-
|
|
283
|
+
/** Suggested redirect: HTTPS (Meta's dashboards accept it) on a port nothing listens on — the user pastes the URL back. */
|
|
284
|
+
const DEFAULT_REDIRECT_URI = 'https://localhost:8765/callback';
|
|
285
|
+
/**
|
|
286
|
+
* Broker-free browser login with the user's own Meta app.
|
|
287
|
+
* Returns null when the user declines (blank app ID) so the caller can fall back to token paste.
|
|
288
|
+
*/
|
|
289
|
+
async function loginWithOwnApp(platform, options, resetApp) {
|
|
290
|
+
const label = platform === 'instagram' ? 'Instagram' : 'Threads';
|
|
291
|
+
// 파이프로 들어온 입력은 예전처럼 토큰이다 (`printf 'IGAA…' | mimi-seed auth instagram`) — 앱 단계를 건너뛴다.
|
|
292
|
+
if (!process.stdin.isTTY)
|
|
293
|
+
return null;
|
|
294
|
+
console.log(M.appHeader(label));
|
|
295
|
+
let app = null;
|
|
296
|
+
if (!resetApp) {
|
|
297
|
+
try {
|
|
298
|
+
app = loadMetaApp(platform);
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
// 손상된 meta-apps.json 때문에 명령 전체가 죽지 않게 — 토큰 입력으로 계속한다 (파일은 건드리지 않는다).
|
|
302
|
+
console.error(M.appLoadFailed(error instanceof Error ? error.message : String(error)));
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const isNew = !app;
|
|
307
|
+
if (app) {
|
|
308
|
+
console.log(M.appSaved(label, app.appId));
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
for (const line of platform === 'instagram' ? M.igAppSteps : M.thAppSteps)
|
|
312
|
+
console.log(line);
|
|
313
|
+
console.log(M.redirectSuggest(DEFAULT_REDIRECT_URI));
|
|
314
|
+
console.log('');
|
|
315
|
+
const appId = await ask(M.askAppId(label));
|
|
316
|
+
if (!appId)
|
|
317
|
+
return null;
|
|
318
|
+
if (looksLikeToken(appId)) {
|
|
319
|
+
console.log(M.tokenAtAppId);
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
if (!isValidAppId(appId)) {
|
|
323
|
+
console.error(M.badAppId);
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
const appSecret = await askHidden(M.askAppSecret(label));
|
|
327
|
+
if (!isValidAppSecret(appSecret)) {
|
|
328
|
+
console.error(M.badAppSecret);
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
const redirectUri = (await ask(M.askRedirect(DEFAULT_REDIRECT_URI))) || DEFAULT_REDIRECT_URI;
|
|
332
|
+
if (!isValidRedirectUri(redirectUri)) {
|
|
333
|
+
console.error(M.badRedirect);
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
app = { appId, appSecret, redirectUri };
|
|
337
|
+
}
|
|
338
|
+
const loopback = isLoopbackRedirect(app.redirectUri);
|
|
339
|
+
console.log(loopback ? M.loopbackWait : M.pasteHow);
|
|
340
|
+
try {
|
|
341
|
+
const result = await connectWithMetaApp(platform, {
|
|
342
|
+
...options,
|
|
343
|
+
app,
|
|
344
|
+
onUrl: (url) => { console.log(M.thUrl); console.log(url); },
|
|
345
|
+
readRedirect: loopback ? undefined : () => ask(M.pastePrompt),
|
|
346
|
+
});
|
|
347
|
+
console.log(indent(result.text));
|
|
348
|
+
// Save the app only once it has produced a verified login, so a typo is never persisted. The account is
|
|
349
|
+
// already saved at this point, so a failed app save is reported, not turned into a failed login.
|
|
350
|
+
if (isNew) {
|
|
351
|
+
try {
|
|
352
|
+
saveMetaApp(platform, app);
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
console.error(M.appSaveFailed(error instanceof Error ? error.message : String(error)));
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return true;
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
if (error instanceof MetaDirectLoginError) {
|
|
362
|
+
console.error(M.directFailed(error.code));
|
|
363
|
+
// validation 의 detail 은 연결 검증 결과 원문(MCP 도구와 같은 문구)이라 'Meta 응답' 접두 없이 그대로 보인다.
|
|
364
|
+
if (error.detail)
|
|
365
|
+
console.error(error.code === 'validation' ? indent(error.detail) : M.directReason(error.detail));
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async function setupInstagram(profile, manualToken = false, resetApp = false) {
|
|
175
372
|
console.log('');
|
|
176
373
|
console.log(M.igHeader);
|
|
177
374
|
const options = { profile };
|
|
@@ -182,7 +379,7 @@ async function setupInstagram(profile, manualToken = false) {
|
|
|
182
379
|
if (existing && !(await confirmReconnect('Instagram', existing.username ?? existing.userId))) {
|
|
183
380
|
return true;
|
|
184
381
|
}
|
|
185
|
-
if (!manualToken) {
|
|
382
|
+
if (!manualToken && socialBrokerBase()) {
|
|
186
383
|
console.log(M.igBrowser);
|
|
187
384
|
try {
|
|
188
385
|
const result = await connectInstagramInBrowser({ ...options, onUrl: (url) => { console.log(M.thUrl); console.log(url); console.log(M.thResume); } });
|
|
@@ -197,6 +394,11 @@ async function setupInstagram(profile, manualToken = false) {
|
|
|
197
394
|
return false;
|
|
198
395
|
}
|
|
199
396
|
}
|
|
397
|
+
if (!manualToken) {
|
|
398
|
+
const direct = await loginWithOwnApp('instagram', options, resetApp);
|
|
399
|
+
if (direct !== null)
|
|
400
|
+
return direct;
|
|
401
|
+
}
|
|
200
402
|
console.log(M.igHowTo);
|
|
201
403
|
console.log(M.igIgaa);
|
|
202
404
|
console.log(M.igEaa);
|
|
@@ -216,7 +418,7 @@ async function setupInstagram(profile, manualToken = false) {
|
|
|
216
418
|
console.log(M.notSaved);
|
|
217
419
|
return result.ok;
|
|
218
420
|
}
|
|
219
|
-
async function setupThreads(profile, manualToken = false) {
|
|
421
|
+
async function setupThreads(profile, manualToken = false, resetApp = false) {
|
|
220
422
|
console.log('');
|
|
221
423
|
console.log(M.thHeader);
|
|
222
424
|
const options = { profile };
|
|
@@ -239,7 +441,7 @@ async function setupThreads(profile, manualToken = false) {
|
|
|
239
441
|
console.log(M.thRefreshFallback);
|
|
240
442
|
}
|
|
241
443
|
}
|
|
242
|
-
if (!manualToken) {
|
|
444
|
+
if (!manualToken && socialBrokerBase()) {
|
|
243
445
|
console.log(M.thBrowser);
|
|
244
446
|
try {
|
|
245
447
|
const result = await connectThreadsInBrowser({ ...options, onUrl: (url) => { console.log(M.thUrl); console.log(url); console.log(M.thResume); } });
|
|
@@ -254,6 +456,11 @@ async function setupThreads(profile, manualToken = false) {
|
|
|
254
456
|
return false;
|
|
255
457
|
}
|
|
256
458
|
}
|
|
459
|
+
if (!manualToken) {
|
|
460
|
+
const direct = await loginWithOwnApp('threads', options, resetApp);
|
|
461
|
+
if (direct !== null)
|
|
462
|
+
return direct;
|
|
463
|
+
}
|
|
257
464
|
console.log(M.thHowTo);
|
|
258
465
|
console.log(M.thStep1);
|
|
259
466
|
console.log(M.thStep2);
|
|
@@ -283,14 +490,16 @@ function indent(text) {
|
|
|
283
490
|
async function main() {
|
|
284
491
|
const args = process.argv.slice(2);
|
|
285
492
|
const manualToken = args.includes('--manual-token');
|
|
493
|
+
const resetApp = args.includes('--reset-app');
|
|
494
|
+
const FLAGS = new Set(['--profile', '--manual-token', '--reset-app']);
|
|
286
495
|
const profileIndex = args.indexOf('--profile');
|
|
287
496
|
const profile = profileIndex >= 0 ? args[profileIndex + 1] : undefined;
|
|
288
497
|
if (profileIndex >= 0 && !profile) {
|
|
289
498
|
console.error(M.invalidArgs);
|
|
290
499
|
process.exit(1);
|
|
291
500
|
}
|
|
292
|
-
const positional = args.filter((arg, index) => arg
|
|
293
|
-
if (positional.length > 1 || args.some((arg) => arg.startsWith('--') && arg
|
|
501
|
+
const positional = args.filter((arg, index) => !FLAGS.has(arg) && (profileIndex < 0 || index !== profileIndex + 1));
|
|
502
|
+
if (positional.length > 1 || args.some((arg) => arg.startsWith('--') && !FLAGS.has(arg))) {
|
|
294
503
|
console.error(M.invalidArgs);
|
|
295
504
|
process.exit(1);
|
|
296
505
|
}
|
|
@@ -302,15 +511,15 @@ async function main() {
|
|
|
302
511
|
ok = await setupFacebook(profile);
|
|
303
512
|
}
|
|
304
513
|
else if (target === 'instagram' || target === 'ig') {
|
|
305
|
-
ok = await setupInstagram(profile, manualToken);
|
|
514
|
+
ok = await setupInstagram(profile, manualToken, resetApp);
|
|
306
515
|
}
|
|
307
516
|
else if (target === 'threads' || target === 'th') {
|
|
308
|
-
ok = await setupThreads(profile, manualToken);
|
|
517
|
+
ok = await setupThreads(profile, manualToken, resetApp);
|
|
309
518
|
}
|
|
310
519
|
else if (target === 'all' || target === 'meta') {
|
|
311
520
|
const fb = await setupFacebook(profile);
|
|
312
|
-
const ig = await setupInstagram(profile, manualToken);
|
|
313
|
-
const th = await setupThreads(profile, manualToken);
|
|
521
|
+
const ig = await setupInstagram(profile, manualToken, resetApp);
|
|
522
|
+
const th = await setupThreads(profile, manualToken, resetApp);
|
|
314
523
|
ok = fb && ig && th;
|
|
315
524
|
}
|
|
316
525
|
else {
|
|
@@ -319,19 +528,19 @@ async function main() {
|
|
|
319
528
|
if (c === 'f')
|
|
320
529
|
ok = await setupFacebook(profile);
|
|
321
530
|
else if (c === 'i')
|
|
322
|
-
ok = await setupInstagram(profile, manualToken);
|
|
531
|
+
ok = await setupInstagram(profile, manualToken, resetApp);
|
|
323
532
|
else if (c === 't')
|
|
324
|
-
ok = await setupThreads(profile, manualToken);
|
|
533
|
+
ok = await setupThreads(profile, manualToken, resetApp);
|
|
325
534
|
else if (c === 'b') {
|
|
326
535
|
// 기존 b=Facebook+Instagram 동작을 유지한다.
|
|
327
536
|
const fb = await setupFacebook(profile);
|
|
328
|
-
const ig = await setupInstagram(profile, manualToken);
|
|
537
|
+
const ig = await setupInstagram(profile, manualToken, resetApp);
|
|
329
538
|
ok = fb && ig;
|
|
330
539
|
}
|
|
331
540
|
else if (c === 'a') {
|
|
332
541
|
const fb = await setupFacebook(profile);
|
|
333
|
-
const ig = await setupInstagram(profile, manualToken);
|
|
334
|
-
const th = await setupThreads(profile, manualToken);
|
|
542
|
+
const ig = await setupInstagram(profile, manualToken, resetApp);
|
|
543
|
+
const th = await setupThreads(profile, manualToken, resetApp);
|
|
335
544
|
ok = fb && ig && th;
|
|
336
545
|
}
|
|
337
546
|
else {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { socialBrokerBase } from '../social/broker-base.js';
|
|
1
2
|
import { createServer } from 'node:http';
|
|
2
3
|
import { randomBytes, createHash, timingSafeEqual } from 'node:crypto';
|
|
3
4
|
import { fetchWithTimeout } from '../lib/http.js';
|
|
@@ -16,10 +17,10 @@ export async function connectThreadsInBrowser(options = {}) {
|
|
|
16
17
|
// Freeze the selected profile before any asynchronous work / directory changes.
|
|
17
18
|
const target = resolveSocialConfigTarget('threads', options);
|
|
18
19
|
const saveOptions = { ...options, profile: target.profile ?? undefined, startDir: options.startDir ?? process.cwd() };
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
20
|
+
const url = socialBrokerBase(options.webBase ?? process.env.MIMI_SEED_WEB_BASE);
|
|
21
|
+
if (!url)
|
|
21
22
|
throw new ThreadsLoginError('configuration');
|
|
22
|
-
|
|
23
|
+
const base = new URL(url);
|
|
23
24
|
const state = randomBytes(32).toString('hex');
|
|
24
25
|
const verifier = randomBytes(32).toString('base64url');
|
|
25
26
|
const codeChallenge = createHash('sha256').update(verifier).digest('base64url');
|