{"record":{"id":"092a008a993cf18d","repo":"crewAIInc/crewAI","slug":"error-fetching-oauth2-configuration-e-s","errorCode":null,"errorMessage":"Error fetching OAuth2 configuration: {e!s}","messagePattern":"Error fetching OAuth2 configuration: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/cli/src/crewai_cli/enterprise/main.py","lineNumber":68,"sourceCode":"            response = httpx.get(oauth_endpoint, timeout=30, headers=headers)\n            response.raise_for_status()\n\n            try:\n                oauth_config = response.json()\n            except json.JSONDecodeError as e:\n                raise ValueError(f\"Invalid JSON response from {oauth_endpoint}\") from e\n\n            self._validate_oauth_config(oauth_config)\n\n            console.print(\n                \"✅ Successfully retrieved OAuth2 configuration\", style=\"green\"\n            )\n            return cast(dict[str, Any], oauth_config)\n\n        except httpx.HTTPError as e:\n            raise ValueError(f\"Failed to connect to enterprise URL: {e!s}\") from e\n        except Exception as e:\n            raise ValueError(f\"Error fetching OAuth2 configuration: {e!s}\") from e\n\n    def _update_oauth_settings(\n        self, enterprise_url: str, oauth_config: dict[str, Any]\n    ) -> None:\n        try:\n            config_mapping = {\n                \"enterprise_base_url\": enterprise_url,\n                \"oauth2_provider\": oauth_config[\"provider\"],\n                \"oauth2_audience\": oauth_config[\"audience\"],\n                \"oauth2_client_id\": oauth_config[\"device_authorization_client_id\"],\n                \"oauth2_domain\": oauth_config[\"domain\"],\n                \"oauth2_extra\": oauth_config[\"extra\"],\n            }\n\n            console.print(\"🔄 Updating local OAuth2 configuration...\")\n\n            for key, value in config_mapping.items():\n                self.settings_command.set(key, value)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/cli/src/crewai_cli/enterprise/main.py#L50-L86","documentation":"A catch-all ValueError raised by the enterprise OAuth2 discovery flow when any exception other than httpx.HTTPError or the handled JSON decode path escapes — for example a failure inside _validate_oauth_config, a KeyError on response shape, or an unexpected bug in response handling. The original exception is chained (`from e`) so the cause is preserved, but the message only says 'Error fetching OAuth2 configuration: <str(e)>'.","triggerScenarios":"`crewai enterprise connect <url>` succeeding at HTTP level but failing afterwards: _validate_oauth_config raising (missing fields — which produces its own message, but validation KeyErrors like oauth_config['provider'] on a non-dict JSON do not), a JSON body that is a list/string instead of an object, or any unexpected type error while processing the response.","commonSituations":"Enterprise server returning well-formed JSON of the wrong shape (array, or object missing 'provider'), partial deployments where the discovery endpoint exists but the config backend is not fully configured, or version skew between CLI and server discovery schema.","solutions":["Read the chained cause: run with the original exception visible (e.g. python -c or check traceback) to see what str(e) actually was","curl the discovery endpoint and check the JSON is an object containing audience, domain, provider, device_authorization_client_id, extra","Update the CLI (uv tool upgrade crewai) in case of schema skew with a newer enterprise server","Report to the enterprise admin if the server emits an unexpected discovery document shape"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import httpx\n\ndef discovery_shape_ok(url: str) -> bool:\n    r = httpx.get(url, timeout=30)\n    r.raise_for_status()\n    doc = r.json()\n    return isinstance(doc, dict) and \"provider\" in doc","typeGuard":"def is_discovery_doc(value: object) -> bool:\n    return isinstance(value, dict) and isinstance(value.get(\"provider\"), str)","tryCatchPattern":"try:\n    enterprise_cmd.connect(url)\nexcept ValueError as e:\n    cause = e.__cause__\n    # inspect cause for the real failure (KeyError, TypeError, ...)\n    log.warning(\"connect failed: %s (cause: %r)\", e, cause)","preventionTips":["Always inspect the chained __cause__ — the wrapper message hides the real error","Check the discovery document is a JSON object with a provider key before connect","Keep CLI and enterprise server versions aligned"],"tags":["enterprise","oauth","validation","error-handling"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}