Skip to content

Use auth.tesla.cn token endpoint for the cn region - #188

Merged
Bre77 merged 1 commit into
mainfrom
fm/tfa-cn-token-host
Oct 20, 2026
Merged

Bre77 merged 1 commit into
mainfrom
fm/tfa-cn-token-host

Conversation

@Bre77

@Bre77 Bre77 commented Oct 20, 2026

Copy link
Copy Markdown
Member

Fixes #187.

The authorize URL already switched to auth.tesla.cn for cn, but the code exchange, refresh and partner_login posted to the global fleet-auth.prd.vn.cloud.tesla.com. Tesla's China docs list POST https://auth.tesla.cn/oauth2/v3/token for both third-party and partner tokens (https://developer.tesla.cn/docs/fleet-api/authentication/third-party-tokens, .../partner-tokens). Global docs keep fleet-auth for na/eu.

New TOKEN_URLS in const.py maps region to token URL; the three call sites use it. na/eu URLs are unchanged.

Tests: tests/test_oauth_token_host.py (cn and unchanged na/eu).

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Teslemetry/coderabbit/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: c381574a-bc60-4c0d-80ed-32cfe43e1d8d
📥 Commits

Reviewing files that changed from the base of the PR and between d456585 and 07d4808.

📒 Files selected for processing: 4
  • tesla_fleet_api/const.py
  • tesla_fleet_api/tesla/fleet.py
  • tesla_fleet_api/tesla/oauth.py
  • tests/test_oauth_token_host.py

Included review availability: This review used your included allowance. 7 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 8 reviews per hour.

📝 Walkthrough

OAuth token requests now use region-specific endpoints for code exchange, token refresh, and partner login. The North America endpoint is the fallback when the configured region has no mapping.

Changes: Regional OAuth token routing

Layer / File(s) Summary
Define regional token endpoints
tesla_fleet_api/const.py
Adds a public mapping for North America, Europe, and China token endpoints.
Route token requests by region
tesla_fleet_api/tesla/oauth.py, tesla_fleet_api/tesla/fleet.py, tests/test_oauth_token_host.py
Code exchange, token refresh, and partner login use the mapped endpoint, with a North America fallback. Tests assert the expected endpoints for North America, Europe, and China.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 07d48

China-region clients will use the China token endpoint, and the na and eu regions keep their existing endpoint. No merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly states the main change: use the China-specific Tesla token endpoint for the cn region.
Description check Passed The description accurately explains the regional token endpoint changes, preserved na/eu behavior, tests, and related issue.
Linked Issues check Passed Issue #187 requires the cn authorization-code exchange, refresh, and partner-token requests to use https://auth.tesla.cn/oauth2/v3/token. The change adds region-specific TOKEN_URLS and applies i…
Out of Scope Changes check Passed The changed files define the regional token mapping, update the three token request paths, and add focused endpoint tests. These changes directly support issue #187. The supplied change summary shows …
Full details: Linked Issues check

Explanation

Issue #187 requires the cn authorization-code exchange, refresh, and partner-token requests to use https://auth.tesla.cn/oauth2/v3/token. The change adds region-specific TOKEN_URLS and applies it to all three call sites. The mapping keeps na and eu on https://fleet-auth.prd.vn.cloud.tesla.com/oauth2/v3/token. Focused tests cover cn and unchanged na/eu behavior.

Full details: Out of Scope Changes check

Explanation

The changed files define the regional token mapping, update the three token request paths, and add focused endpoint tests. These changes directly support issue #187. The supplied change summary shows no unrelated changes.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@Bre77
Bre77 merged commit 0a7c275 into main Oct 20, 2026
7 checks passed
@Bre77
Bre77 deleted the fm/tfa-cn-token-host branch October 20, 2026 05:36
@Bre77 Bre77 mentioned this pull request Oct 20, 2026
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.

CN region: OAuth token endpoint still uses the global auth host instead of auth.tesla.cn

1 participant