Exchange a refresh token for a new access token.
(token_endpoint: str, client_id: str, refresh_token: str)
| 327 | |
| 328 | |
| 329 | def _refresh_token(token_endpoint: str, client_id: str, refresh_token: str) -> dict[str, Any]: |
| 330 | """Exchange a refresh token for a new access token.""" |
| 331 | payload = urlencode( |
| 332 | { |
| 333 | "grant_type": "refresh_token", |
| 334 | "client_id": client_id, |
| 335 | "refresh_token": refresh_token, |
| 336 | } |
| 337 | ).encode() |
| 338 | |
| 339 | req = urllib.request.Request( |
| 340 | token_endpoint, |
| 341 | data=payload, |
| 342 | headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}, |
| 343 | ) |
| 344 | with urllib.request.urlopen(req, timeout=30) as resp: |
| 345 | return json.loads(resp.read()) |
| 346 | |
| 347 | |
| 348 | # --------------------------------------------------------------------------- |