{"record":{"id":"6c42831e883d5923","repo":"langgenius/dify","slug":"client-id-is-invalid","errorCode":null,"errorMessage":"client_id is invalid","messagePattern":"client_id is invalid","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/auth/oauth_server.py","lineNumber":91,"sourceCode":"    OAuthProviderTokenResponse,\n)\n\n\ndef oauth_server_client_id_required[T, **P, R](\n    view: Callable[Concatenate[T, OAuthProviderApp, P], R],\n) -> Callable[Concatenate[T, P], R]:\n    @wraps(view)\n    def decorated(self: T, *args: P.args, **kwargs: P.kwargs) -> R:\n        json_data = request.get_json()\n        if json_data is None:\n            raise BadRequest(\"client_id is required\")\n\n        payload = OAuthClientPayload.model_validate(json_data)\n        client_id = payload.client_id\n\n        oauth_provider_app = OAuthServerService.get_oauth_provider_app(client_id)\n        if not oauth_provider_app:\n            raise NotFound(\"client_id is invalid\")\n\n        return view(self, oauth_provider_app, *args, **kwargs)\n\n    return decorated\n\n\ndef oauth_server_access_token_required[T, **P, R](\n    view: Callable[Concatenate[T, OAuthProviderApp, Account, P], R],\n) -> Callable[Concatenate[T, OAuthProviderApp, P], R | ResponseReturnValue]:\n    @wraps(view)\n    def decorated(\n        self: T, oauth_provider_app: OAuthProviderApp, *args: P.args, **kwargs: P.kwargs\n    ) -> R | ResponseReturnValue:\n        if not isinstance(oauth_provider_app, OAuthProviderApp):\n            raise BadRequest(\"Invalid oauth_provider_app\")\n\n        authorization_header = request.headers.get(\"Authorization\")\n        if not authorization_header:","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/auth/oauth_server.py#L73-L109","documentation":"Flask NotFound (HTTP 404) raised at oauth_server.py:91 by the oauth_server_client_id_required decorator after OAuthServerService.get_oauth_provider_app(client_id) returns a falsy value — no OAuthProviderApp row matches the supplied client_id. The body was valid JSON and parsed into OAuthClientPayload, but the client_id does not correspond to a registered provider app.","triggerScenarios":"POST to any /console/api/oauth/provider* endpoint with a JSON body whose client_id is not registered, was deleted, or has a typo. get_oauth_provider_app returns None/empty -> NotFound.","commonSituations":"Client copied the wrong client_id (e.g. from a different environment), the provider app was rotated/revoked, or the app was never created. Also happens when dev/staging/prod client_ids are mixed up.","solutions":["Verify the client_id against the OAuth provider apps table / admin console and use the correct one for this environment.","If the app was deleted or rotated, register a new OAuthProviderApp and update the client configuration.","Confirm there is no leading/trailing whitespace or encoding issue in the client_id value.","Check that the deployment hosting the endpoint actually has the provider app seeded (env/config mismatch across replicas)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate the client_id is registered before first use; cache the lookup.\nconst apps = await listOAuthProviderApps();\nif (!apps.find(a => a.client_id === cid)) {\n  throw new Error('Unknown client_id for this environment');\n}","typeGuard":"function isValidClientId(id: string): boolean {\n  return typeof id === 'string' && id.trim().length > 0 && /^[A-Za-z0-9_-]+$/.test(id);\n}","tryCatchPattern":"try {\n  await callOAuthServer(cid);\n} catch (e) {\n  if (e.status === 404 && /client_id is invalid/i.test(e.message)) {\n    refreshProviderAppConfig();\n  } else throw e;\n}","preventionTips":["Store client_id per environment to avoid staging/prod mix-ups.","Re-verify the id after any app rotation.","Strip whitespace when copying the id."],"tags":["oauth-server","client-id","not-found","configuration"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}