add images support

This commit is contained in:
timka123 committed 2026-11-23 18:19:24 +03:00
1 parent 2b3518f873
commit d972f4b314
14 files changed
+2157 -51

No files matched your search

+44
View File
@@ -662,6 +662,50 @@ class MCPAuthManager:
return authorize_url, pending
async def validate_cimd_url(self, client_metadata_url: str) -> list[str]:
"""Validate an HTTPS OAuth Client ID Metadata Document URL and return a list of warnings (empty = valid)."""
warnings: list[str] = []
try:
async with httpx.AsyncClient(
timeout=10.0,
follow_redirects=True,
trust_env=not is_loopback_url(client_metadata_url),
) as client:
resp = await client.get(client_metadata_url, headers={"Accept": "application/json"})
except Exception as e:
return [f"Не удалось загрузить `{client_metadata_url}`: {e}"]
if resp.status_code != 200:
return [f"Сервер вернул HTTP {resp.status_code} вместо 200 OK."]
ctype = (resp.headers.get("content-type") or "").lower()
if "application/json" not in ctype:
warnings.append(
f"Сервер отдал `Content-Type: {resp.headers.get('content-type', 'missing')}` вместо `application/json` — "
"строгие OAuth-серверы (например Zenmoney) отклоняют такой файл с `invalid_request` "
"(Gitea/GitHub `/raw/` всегда отдают `text/plain`; отдавайте файл через nginx / GitHub Pages / static host с `application/json`)."
)
try:
doc = resp.json()
except Exception as e:
warnings.append(f"Некорректный JSON: {e}")
return warnings
if not isinstance(doc, dict):
warnings.append("Документ должен быть JSON-объектом.")
return warnings
if doc.get("client_id") != client_metadata_url:
warnings.append(
f"Поле `client_id` в JSON (`{doc.get('client_id')}`) должно точно совпадать с URL (`{client_metadata_url}`)."
)
uris = doc.get("redirect_uris")
if not isinstance(uris, list) or not uris:
warnings.append("В JSON отсутствует непустой массив `redirect_uris`.")
return warnings
async def _resolve_cimd_redirect_uri(
self,
client_metadata_url: str,