refactor(auth): route browser paste login through /perplexity-login
The perplexity_search tool no longer prompts for pasted browser credentials mid-search; /perplexity-login --browser is the single entry point for that flow. Drop the now-unused promptForBrowserAuth option and its Cloudflare-challenge fallback from authenticate().
This commit is contained in:
@@ -39,7 +39,6 @@ export interface AuthenticateOptions {
|
||||
signal?: AbortSignal;
|
||||
promptForEmail?: () => Promise<string | null | undefined>;
|
||||
promptForOtp?: (email: string) => Promise<string | null | undefined>;
|
||||
promptForBrowserAuth?: () => Promise<string | null | undefined>;
|
||||
}
|
||||
|
||||
function normalizeInput(value: string | null | undefined): string | null {
|
||||
@@ -91,16 +90,6 @@ export async function saveBrowserAuthInput(input: string): Promise<StoredToken>
|
||||
return credentials;
|
||||
}
|
||||
|
||||
async function promptForBrowserCredentials(
|
||||
options: AuthenticateOptions,
|
||||
): Promise<StoredToken | null> {
|
||||
const input = normalizeInput(await options.promptForBrowserAuth?.());
|
||||
if (!input) {
|
||||
return null;
|
||||
}
|
||||
return saveBrowserAuthInput(input);
|
||||
}
|
||||
|
||||
function buildAuthHeaders(includeJsonContentType = false): Record<string, string> {
|
||||
return {
|
||||
Accept: "application/json",
|
||||
@@ -297,11 +286,6 @@ export async function authenticate(options: AuthenticateOptions = {}): Promise<S
|
||||
normalizeInput(process.env.PI_PERPLEXITY_EMAIL) ??
|
||||
normalizeInput(await options.promptForEmail?.());
|
||||
if (!email) {
|
||||
const browserCredentials = await promptForBrowserCredentials(options);
|
||||
if (browserCredentials) {
|
||||
return browserCredentials;
|
||||
}
|
||||
|
||||
throw new AuthError(
|
||||
"NO_TOKEN",
|
||||
`Could not find a desktop token, browser token/cookie, or email for OTP fallback. ${DESKTOP_AUTH_HELP} ${OTP_AUTH_HELP} ${BROWSER_AUTH_HELP}`,
|
||||
@@ -317,13 +301,6 @@ export async function authenticate(options: AuthenticateOptions = {}): Promise<S
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (error instanceof BrowserChallengeError) {
|
||||
const browserCredentials = await promptForBrowserCredentials(options);
|
||||
if (browserCredentials) {
|
||||
return browserCredentials;
|
||||
}
|
||||
}
|
||||
|
||||
throw new AuthError(
|
||||
"EXTRACTION_FAILED",
|
||||
`Email OTP authentication failed: ${errorMessage(error)}. ${OTP_AUTH_HELP} ${BROWSER_AUTH_HELP}`,
|
||||
|
||||
@@ -107,7 +107,7 @@ export function registerPerplexityCommands(pi: ExtensionAPI): void {
|
||||
return;
|
||||
}
|
||||
|
||||
await authenticate({ promptForEmail, promptForOtp, promptForBrowserAuth });
|
||||
await authenticate({ promptForEmail, promptForOtp });
|
||||
ctx.ui.notify("Perplexity login successful. Token saved.", "info");
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError && error.code === "NO_TOKEN") {
|
||||
|
||||
@@ -5,7 +5,6 @@ import { Type } from "@sinclair/typebox";
|
||||
import { registerPerplexityConfigCommand } from "./commands/config.js";
|
||||
import { registerPerplexityCommands } from "./commands/login.js";
|
||||
|
||||
import { browserLoginInstructions } from "./auth/browser.js";
|
||||
import { authenticate } from "./auth/login.js";
|
||||
import { loadConfig, resolveSearchDefaults } from "./config.js";
|
||||
import { formatForLLM } from "./search/format.js";
|
||||
@@ -58,13 +57,6 @@ export default function (pi: ExtensionAPI) {
|
||||
...(signal !== undefined ? { signal } : {}),
|
||||
promptForEmail: async () => promptInput("Perplexity email", "you@example.com"),
|
||||
promptForOtp: async (email) => promptInput(`Enter OTP sent to ${email}`, "123456"),
|
||||
promptForBrowserAuth: async () => {
|
||||
ctx?.ui?.notify?.(browserLoginInstructions(), "info");
|
||||
return promptInput(
|
||||
"Paste copied cURL command or Cookie header",
|
||||
"curl 'https://www.perplexity.ai/' -H 'Cookie: ...'",
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
if (signal?.aborted) {
|
||||
|
||||
Reference in New Issue
Block a user