Pull a usable token dict out of Claude Code's on-disk shapes. Resolution order matches the original handler: 1. ``claudeAiOauth`` nested object (current Claude Code CLI format). 2. Top-level ``accessToken`` (legacy). 3. Top-level ``oauthToken`` (emulator format) — copied to
(raw: dict[str, Any])
| 71 | |
| 72 | |
| 73 | def _normalize_credentials(raw: dict[str, Any]) -> dict[str, Any] | None: |
| 74 | """Pull a usable token dict out of Claude Code's on-disk shapes. |
| 75 | |
| 76 | Resolution order matches the original handler: |
| 77 | 1. ``claudeAiOauth`` nested object (current Claude Code CLI format). |
| 78 | 2. Top-level ``accessToken`` (legacy). |
| 79 | 3. Top-level ``oauthToken`` (emulator format) — copied to |
| 80 | ``accessToken`` so downstream code only checks one key. |
| 81 | """ |
| 82 | if "claudeAiOauth" in raw: |
| 83 | oauth = raw["claudeAiOauth"] |
| 84 | if isinstance(oauth, dict) and _is_valid_oauth_token(oauth.get("accessToken", "")): |
| 85 | return oauth |
| 86 | token = raw.get("accessToken") or raw.get("oauthToken", "") |
| 87 | if _is_valid_oauth_token(token): |
| 88 | if "oauthToken" in raw and "accessToken" not in raw: |
| 89 | raw["accessToken"] = raw["oauthToken"] |
| 90 | return raw |
| 91 | return None |
| 92 | |
| 93 | |
| 94 | def _load_credentials_from_disk(path: Path) -> dict[str, Any] | None: |
no test coverage detected