MCPcopy
hub / github.com/opentrace/opentrace / _exchange_code

Function _exchange_code

agent/src/opentrace_agent/cli/auth.py:302–326  ·  view source on GitHub ↗

Exchange an authorization code for tokens.

(
    token_endpoint: str,
    client_id: str,
    code: str,
    verifier: str,
    redirect_uri: str,
)

Source from the content-addressed store, hash-verified

300
301
302def _exchange_code(
303 token_endpoint: str,
304 client_id: str,
305 code: str,
306 verifier: str,
307 redirect_uri: str,
308) -> dict[str, Any]:
309 """Exchange an authorization code for tokens."""
310 payload = urlencode(
311 {
312 "grant_type": "authorization_code",
313 "client_id": client_id,
314 "code": code,
315 "redirect_uri": redirect_uri,
316 "code_verifier": verifier,
317 }
318 ).encode()
319
320 req = urllib.request.Request(
321 token_endpoint,
322 data=payload,
323 headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
324 )
325 with urllib.request.urlopen(req, timeout=30) as resp:
326 return json.loads(resp.read())
327
328
329def _refresh_token(token_endpoint: str, client_id: str, refresh_token: str) -> dict[str, Any]:

Callers 1

loginFunction · 0.85

Calls 1

readMethod · 0.80

Tested by

no test coverage detected