MCPcopy Create free account
hub / github.com/BitterSecurity/Decepticon / _normalize_credentials

Function _normalize_credentials

config/claude_code_handler.py:73–91  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

71
72
73def _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
94def _load_credentials_from_disk(path: Path) -> dict[str, Any] | None:

Callers 1

Calls 2

_is_valid_oauth_tokenFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected