Dynamically register a new OAuth client.
(registration_endpoint: str, redirect_uris: list[str])
| 112 | |
| 113 | |
| 114 | def _register_client(registration_endpoint: str, redirect_uris: list[str]) -> dict[str, Any]: |
| 115 | """Dynamically register a new OAuth client.""" |
| 116 | body = json.dumps( |
| 117 | { |
| 118 | "client_name": CLIENT_NAME, |
| 119 | "redirect_uris": redirect_uris, |
| 120 | "grant_types": ["authorization_code"], |
| 121 | "response_types": ["code"], |
| 122 | "scope": SCOPES, |
| 123 | "token_endpoint_auth_method": "none", |
| 124 | } |
| 125 | ).encode() |
| 126 | |
| 127 | req = urllib.request.Request( |
| 128 | registration_endpoint, |
| 129 | data=body, |
| 130 | headers={"Content-Type": "application/json", "Accept": "application/json"}, |
| 131 | ) |
| 132 | with urllib.request.urlopen(req, timeout=15) as resp: |
| 133 | client = json.loads(resp.read()) |
| 134 | |
| 135 | if "client_id" not in client: |
| 136 | raise RuntimeError("Dynamic registration response missing client_id") |
| 137 | |
| 138 | save_client(client) |
| 139 | return client |
| 140 | |
| 141 | |
| 142 | def _ensure_client(disco: dict[str, Any], redirect_uris: list[str]) -> dict[str, Any]: |
no test coverage detected