Skip to content

Fix Xiaomi login with two-step verification - #2766

Open
kingnum wants to merge 2 commits into
AlexxIT:masterfrom
kingnum:fix/xiaomi-2fa-login
Open

kingnum wants to merge 2 commits into
AlexxIT:masterfrom
kingnum:fix/xiaomi-2fa-login

Conversation

@kingnum

@kingnum kingnum commented Nov 28, 2026

Copy link
Copy Markdown

Problem

When Xiaomi requires two-step verification (SMS/email), serviceLoginAuth2 returns a notificationUrl and login continues in LoginWithVerify. After the code is accepted, Xiaomi redirects to a confirm page (/fe/service/verifyPhone) and does not set userId/passToken on that redirect.

finishAuth stopped at that page, so apiAuth saved empty credentials:

xiaomi:
  "": ""

Add > Xiaomi then showed an empty account ID and Load devices returned no cameras, even though the login appeared successful.

Fix

  • Use a cookie jar for the Xiaomi cloud client so the verification session (identity_session) survives redirects.
  • After following the verification location, follow the confirmUrl (or skipUrl) query parameter from the confirm page. That chain sets userId, cUserId, serviceToken and passToken.
  • Refuse to persist empty credentials; return an error instead of writing xiaomi: "": "".

Testing

  • go vet ./pkg/xiaomi/... ./internal/xiaomi/...
  • go test ./pkg/xiaomi/... ./internal/xiaomi/...
  • Manually tested with Xiaomi Smart Camera 4 Zoom Edition (xiaomi.camera.083ac1), region cn, email login + phone SMS verification. Device list loads and a stream URL is generated.

Note: passToken expiry (~3 days) is a separate existing limitation and is not addressed here.

🤖 Generated with Claude Code

yangliuqing and others added 2 commits November 28, 2026 11:30
Xiaomi redirects to a confirm page after SMS/email verification and
doesn't set userId/passToken on that redirect. Keep auth cookies across
redirects, follow confirmUrl/skipUrl, and don't save empty credentials.

Tested with Xiaomi Smart Camera 4 Zoom Edition (xiaomi.camera.083ac1).

Co-Authored-By: Claude Code <noreply@anthropic.com>
A Cloud object created before login has no valid session, but it was
cached by userID and reused after a successful login. Device list and
stream requests then kept failing with 401 Unauthorized until restart.

Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant