Skip to content

fix(auth): hex-decode credentials, close keep-alive sockets, fix MCP list_devices schema#51

Merged
chenliuyun merged 3 commits into
mainfrom
fix/auth-decrypt-hex-encoding
May 22, 2026
Merged

fix(auth): hex-decode credentials, close keep-alive sockets, fix MCP list_devices schema#51
chenliuyun merged 3 commits into
mainfrom
fix/auth-decrypt-hex-encoding

Conversation

@chenliuyun
Copy link
Copy Markdown
Collaborator

Summary

  • token-exchange: decryptField returns decrypted bytes as hex string (.toString('hex')) — verified working against live SwitchBot API
  • oauth-callback: call closeAllConnections() in all termination paths (success, OAuth error, timeout) so browser keep-alive sockets don't prevent the CLI process from exiting after login
  • mcp: relax hubDeviceId to z.string().nullable().optional() in both deviceList and infraredRemoteList output schemas — fixes list_devices MCP tool schema validation failure when API returns null/absent hubDeviceId

Test plan

  • tests/auth/oauth-callback.test.ts — 3 new keep-alive teardown tests added; regression-verified: removing closeAllConnections causes these tests to fail
  • All 12 oauth-callback tests pass (npm test -- tests/auth/oauth-callback.test.ts)
  • switchbot auth login — browser OAuth flow completes, credentials verified and saved, process exits cleanly
  • switchbot devices list — API auth works with hex-decoded credentials
  • MCP list_devices — schema accepts null hubDeviceId without validation error

🤖 Generated with Claude Code

chenliuyun and others added 3 commits May 22, 2026 14:25
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…list_devices schema

- token-exchange: return decrypted bytes as hex string (verified working with live API)
- oauth-callback: call closeAllConnections() in all termination paths so browser
  keep-alive sockets don't prevent the CLI process from exiting after login
- mcp: relax hubDeviceId to nullable().optional() in both deviceList and
  infraredRemoteList output schemas — fixes list_devices tool schema validation
  failure when API returns null/missing hubDeviceId
- tests: add keep-alive teardown tests that regress the closeAllConnections fix

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e with real API

The Wonder API encrypts credentials as raw binary bytes. Calling .toString('utf8')
on the decrypted output produced garbled non-ASCII characters that broke HTTP
header validation. The correct output is .toString('hex').

The previous test fixture used a UTF-8 string as the plaintext credential, which
did not reflect the real API's binary payload format and caused the test to fail
after the encoding fix. Updated the fixture to:
- Use fixed binary buffers as the plaintext (matching actual Wonder API behavior)
- Encrypt raw bytes (not UTF-8-encoded strings) to simulate server-side encryption
- Assert the output is a lowercase hex string safe for HTTP headers and HMAC keys
- Add length assertions matching observed live token/secret sizes (96/32 chars)
- Add a comment block explaining WHY .toString('hex') is correct, to prevent
  future reviewers from incorrectly flagging this as a regression

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chenliuyun chenliuyun merged commit 6f5367a into main May 22, 2026
11 checks passed
chenliuyun pushed a commit that referenced this pull request May 22, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chenliuyun chenliuyun deleted the fix/auth-decrypt-hex-encoding branch May 22, 2026 15:37
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