Skip to content

feat: add Tampermonkey userscript for AI Studio auth extraction#125

Open
xjetry wants to merge 1 commit into
iBUHub:mainfrom
xjetry:feat/extract-auth-userscript
Open

feat: add Tampermonkey userscript for AI Studio auth extraction#125
xjetry wants to merge 1 commit into
iBUHub:mainfrom
xjetry:feat/extract-auth-userscript

Conversation

@xjetry
Copy link
Copy Markdown

@xjetry xjetry commented Apr 11, 2026

Summary

  • Add a Tampermonkey userscript (scripts/auth/extract-auth.user.js) that extracts Google AI Studio auth directly from the browser
  • Only extracts the 9 essential Google auth cookies (first-party only, no tracking/analytics cookies)
  • Saves as {email}.json compatible with AIStudioToAPI's configs/auth/auth-N.json format
  • Zero localStorage extraction needed — server-side doesn't check it

How it works

  1. Install the userscript in Tampermonkey
  2. Configure Tampermonkey: Settings → Advanced → Security → "Allow scripts to access cookies" → All
  3. Visit aistudio.google.com (logged in)
  4. Click the "📦 Extract Auth" button → downloads {email}.json
  5. Rename to auth-N.json and place in configs/auth/

Minimal cookie set (9 cookies)

Cookie Purpose
SID Primary session
HSID HTTP session binding
SSID Secure session binding
SAPISID SAPISIDHASH calculation
SIDCC Consent
__Secure-1PSID HTTPS primary session
__Secure-1PAPISID HTTPS API auth
__Secure-1PSIDCC HTTPS consent
__Secure-1PSIDTS Session timestamp

Why not more cookies?

  • __Secure-3P* variants are for third-party contexts — Playwright visits AI Studio as first-party
  • NID is Google Search preferences — not needed for auth
  • _ga* / _gcl_au are Google Analytics/Ads tracking
  • localStorage items are regenerated by AI Studio on page load

Test plan

  • Install userscript in Tampermonkey with GM_cookie enabled
  • Verify button appears on aistudio.google.com
  • Click button and confirm JSON download with correct email filename
  • Rename to auth-N.json, place in configs/auth/, verify AIStudioToAPI can use it

Minimal browser-side auth extractor that runs on aistudio.google.com.
Extracts only the 9 essential Google auth cookies via GM_cookie API
and saves as {email}.json compatible with AIStudioToAPI's auth format.
@bbbugg
Copy link
Copy Markdown
Member

bbbugg commented Apr 11, 2026

这个方式提取的 auth 有效期你试过没?之前看过这种方法,听说过期很快?

@xjetry
Copy link
Copy Markdown
Author

xjetry commented Apr 11, 2026

试过可用,有效期还没有验证

@Luojiyu
Copy link
Copy Markdown

Luojiyu commented Apr 20, 2026

我试了一下有效期大概在1天左右,比较短

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants