fix(auth): address browser cookie review comments
This commit is contained in:
@@ -23,7 +23,7 @@ pi install github:ivanrvpereira/pi-perplexity
|
|||||||
|
|
||||||
Run login once:
|
Run login once:
|
||||||
|
|
||||||
```
|
```text
|
||||||
/perplexity-login
|
/perplexity-login
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ This usually reuses an existing cached login, borrows the Perplexity macOS app l
|
|||||||
|
|
||||||
If login fails with a Cloudflare “Just a moment...” page, use browser login instead:
|
If login fails with a Cloudflare “Just a moment...” page, use browser login instead:
|
||||||
|
|
||||||
```
|
```text
|
||||||
/perplexity-login --browser
|
/perplexity-login --browser
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -100,7 +100,7 @@ function extractCookieHeader(input: string): string {
|
|||||||
return quotedCurlCookieOption.trim();
|
return quotedCurlCookieOption.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
const unquotedCurlCookieOption = trimmed.match(/(?:^|\s)(?:-b|--cookie)=([^\s\\]+)/i)?.[1];
|
const unquotedCurlCookieOption = trimmed.match(/(?:^|\s)(?:-b|--cookie)(?:=|\s+)([^\s\\]+)/i)?.[1];
|
||||||
if (unquotedCurlCookieOption) {
|
if (unquotedCurlCookieOption) {
|
||||||
return unquotedCurlCookieOption.trim();
|
return unquotedCurlCookieOption.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,6 +366,19 @@ describe("auth/login", () => {
|
|||||||
expect(parsed?.access).toBe(browserToken);
|
expect(parsed?.access).toBe(browserToken);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("parseBrowserAuthInput extracts cookies from unquoted -b and --cookie cURL forms", async () => {
|
||||||
|
const browserToken = createJwt(Date.now() + 2 * 60 * 60 * 1000);
|
||||||
|
const { parseBrowserAuthInput } = await importLoginModule();
|
||||||
|
|
||||||
|
for (const flag of ["-b", "--cookie"]) {
|
||||||
|
const curl = `curl 'https://www.perplexity.ai/rest/sse/perplexity_ask' ${flag} __Secure-next-auth.session-token=${browserToken}`;
|
||||||
|
const parsed = parseBrowserAuthInput(curl);
|
||||||
|
|
||||||
|
expect(parsed?.cookies).toBe(`__Secure-next-auth.session-token=${browserToken}`);
|
||||||
|
expect(parsed?.access).toBe(browserToken);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("saveBrowserAuthInput explains Copy as cURL without cookies", async () => {
|
test("saveBrowserAuthInput explains Copy as cURL without cookies", async () => {
|
||||||
const curl = `curl 'https://www.perplexity.ai/' \\
|
const curl = `curl 'https://www.perplexity.ai/' \\
|
||||||
-H 'Upgrade-Insecure-Requests: 1' \\
|
-H 'Upgrade-Insecure-Requests: 1' \\
|
||||||
|
|||||||
Reference in New Issue
Block a user