from typing import Any from urllib.parse import urlparse # Checks an Authorization Server metadata response against atproto OAuth requirements def is_valid_authserver_meta(obj: dict[str, Any] | None, url: str) -> bool: if obj is None: return False fetch_url = urlparse(url) issuer_url = urlparse(obj["issuer"]) assert issuer_url.hostname == fetch_url.hostname assert issuer_url.scheme == "https" assert issuer_url.port is None assert issuer_url.path in ["", "/"] assert issuer_url.params == "" assert issuer_url.fragment == "" assert "code" in obj["response_types_supported"] assert "authorization_code" in obj["grant_types_supported"] assert "refresh_token" in obj["grant_types_supported"] assert "S256" in obj["code_challenge_methods_supported"] assert "none" in obj["token_endpoint_auth_methods_supported"] assert "private_key_jwt" in obj["token_endpoint_auth_methods_supported"] assert "ES256" in obj["token_endpoint_auth_signing_alg_values_supported"] assert "atproto" in obj["scopes_supported"] assert obj["authorization_response_iss_parameter_supported"] is True assert obj["pushed_authorization_request_endpoint"] is not None assert obj["require_pushed_authorization_requests"] is True assert "ES256" in obj["dpop_signing_alg_values_supported"] if "require_request_uri_registration" in obj: assert obj["require_request_uri_registration"] is True assert obj["client_id_metadata_document_supported"] is True return True