-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrtt.py
More file actions
21 lines (16 loc) · 704 Bytes
/
Copy pathrtt.py
File metadata and controls
21 lines (16 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests
RTT_BASE = "https://data.rtt.io"
def get_auth_headers(refresh_token: str) -> dict[str, str]:
"""Exchange an RTT refresh token for a short-lived access token and return auth headers."""
print("Obtaining API access token...")
r = requests.get(
f"{RTT_BASE}/api/get_access_token",
headers={"Authorization": f"Bearer {refresh_token}"},
timeout=10,
)
if r.status_code != 200:
raise RuntimeError(f"Failed to obtain access token. HTTP {r.status_code}")
access_token = r.json().get("token")
if not access_token:
raise RuntimeError("Invalid or expired refresh token.")
return {"Authorization": f"Bearer {access_token}"}