feat: add headless MSA credentials login - #18
Conversation
Add Config.CredentialsToken, a headless Microsoft-account username/password
login flow for the "LIVE" (login.live.com) environment. It ports RaphiMC/
MinecraftAuth's CredentialsMsaAuthService and returns an *oauth2.Token that
plugs straight into the existing SISU/Xbox Live flow.
Flow:
- GET oauth20_authorize.srf (client_id, scope, redirect_uri=oauth20_desktop.srf,
response_type=code, response_mode=query) over a cookie-jar client.
- Scrape `var ServerData = {...}` for urlPost and the sFTTag PPFT input.
- POST login/loginfmt/passwd/PPFT to urlPost, following redirects.
- Read the authorization code from the final oauth20_desktop.srf?code=... URL
and exchange it (redirect_uri pinned to the desktop URI).
The jar client is a shallow copy of the context client with only Jar added, so
the caller's Transport/timeout are preserved and never mutated. Pure parsing
helpers (ServerData/PPFT/code/error extraction) are factored out and unit
tested; an httptest end-to-end test covers the authorize/POST/redirect/code
path plus the token exchange, and a second covers the wrong-credentials error
path. No test makes a real network call.
Fragility caveat: this scrapes and drives Microsoft's HTML login pages, so it
breaks on 2FA, CAPTCHA, interrupt/consent, or conditional-access, and may break
without notice if Microsoft changes those pages. Device-code and auth-code
flows remain preferred for interactive logins.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_8202c455-2fb6-4184-a5e1-2ec0bad5f9a2) |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Adds a headless Microsoft-account username/password login flow to the
sisupackage:Config.CredentialsToken(ctx, email, password) (*oauth2.Token, error). This is the one capability go-xsapi lacked versus RaphiMC/MinecraftAuth. The returned*oauth2.Tokenplugs straight into the existing SISU/Xbox Live flow (e.g.Config.TokenSource,Config.New).It ports MinecraftAuth's
CredentialsMsaAuthServicefor the LIVE (login.live.com) environment.Flow
oauth20_authorize.srfwithclient_id,scope(the existingMBI_SSLscope const),redirect_uri=https://login.live.com/oauth20_desktop.srf,response_type=code,response_mode=query, over an HTTP client with a cookie jar. The desktop redirect is used (instead ofConfig.RedirectURI, which is anms-xal://scheme) so the final code is readable from the URL.var ServerData = {...}out of the returned HTML and decode it, pullingurlPostand thesFTTagPPFT hidden-input (field name + value).login,loginfmt,passwd,PPFTtourlPost, following redirects (the cookie jar carries the session).codefrom the terminaloauth20_desktop.srf?code=...URL (resp.Request.URL). If it instead lands on a login/interrupt page, the embeddedServerDataerror (sErrorCode/sErrTxt) or aDoSubmitinterrupt dialog is surfaced as a clear error.Config.Exchange, addingscope/client_id, withredirect_uripinned to the desktop URI so Microsoft accepts the exchange).The cookie-jar client is a shallow copy of the context client with only
Jaradded — the caller'sTransport/Timeoutare preserved and the caller's client is never mutated.Testing
extractServerData,parsePPFT,codeFromURL,redirectError,loginError) with realistic fixture strings, including a realisticServerDataHTML snippet, a PPFTsFTTag, a desktop.srf redirect URL with a code, and error/interrupt pages.httptest.Servertest covering the full authorize → POST → redirect → code-extraction → token-exchange path (fakeoauth20_authorize.srf,urlPost,oauth20_desktop.srf, andoauth20_token.srf).gofmt -s,go build ./...,go vet ./xal/sisu/, andgo test ./xal/sisu/are all clean.Fragility caveat
This flow is fragile: it scrapes and drives Microsoft's HTML login pages, so it breaks whenever the account requires two-factor authentication, a CAPTCHA, an interrupt/consent page, or conditional-access policies, and it may break without notice if Microsoft changes those pages. The device-code (
DeviceAuth/DeviceAccessToken) and authorization-code (AuthCodeURL/Exchange) flows remain preferred for interactive logins.CredentialsTokenis intended only for headless, non-interactive accounts you control. This is documented on the method itself.🤖 Generated with Claude Code
Note
High Risk
Introduces credential-based authentication that handles passwords and depends on brittle HTML scraping of Microsoft's login pages, which can break or encourage unsafe usage patterns.
Overview
Adds
Config.CredentialsToken(ctx, email, password)so callers can obtain an*oauth2.Tokenwithout a browser, filling the gap versus MinecraftAuth-style credential login. The flow driveslogin.live.com: fetch authorize HTML, parse embeddedServerData(urlPost+ PPFT), POST credentials over a cookie-jar HTTP client, read the authcodefrom the desktop redirect URI (oauth20_desktop.srf), then exchange it withredirect_uripinned to that desktop URI (parallel to existingExchange).Failure paths surface OAuth query errors,
ServerDatalogin messages, and interrupt/2FA-style pages with explicit guidance to prefer device-code or auth-code flows. Tests cover HTML helpers and fullhttptestsuccess and wrong-password paths via overridable package-level authorize/token URLs.Reviewed by Cursor Bugbot for commit c6156cb. Bugbot is set up for automated code reviews on this repo. Configure here.