{"record":{"id":"6179f2093fd0f276","repo":"Budibase/budibase","slug":"oauth2-auth-config-is-missing-token-url-or-client","errorCode":null,"errorMessage":"OAuth2 auth config is missing token URL or client ID.","messagePattern":"OAuth2 auth config is missing token URL or client ID\\.","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/knowledgeSources/sharepoint/connection.ts","lineNumber":184,"sourceCode":"    datasource = await sdk.datasources.get(datasourceId)\n  } catch {\n    throw new HTTPError(\"SharePoint auth config not found.\", 400)\n  }\n  const authConfigs = datasource.config?.authConfigs as\n    | OAuth2RestAuthConfigWithTokenCache[]\n    | undefined\n  const authConfig = authConfigs?.find(config => config._id === authConfigId)\n  if (!authConfig) {\n    throw new HTTPError(\"SharePoint auth config not found.\", 400)\n  }\n  if (!isOAuth2ClientCredentialsAuthConfig(authConfig)) {\n    throw new HTTPError(\n      \"SharePoint requires an OAuth2 client credentials auth config.\",\n      400\n    )\n  }\n  if (!authConfig.url || !authConfig.clientId) {\n    throw new HTTPError(\n      \"OAuth2 auth config is missing token URL or client ID.\",\n      400\n    )\n  }\n  return authConfig\n}\n\nexport const getSharePointBearerToken = async (\n  datasourceId: string,\n  authConfigId: string\n): Promise<string> => {\n  const connection = await readConnection(datasourceId, authConfigId)\n  return sdk.oauth2.getTokenFromConfig(`${datasourceId}:${authConfigId}`, {\n    url: connection.url,\n    clientId: connection.clientId,\n    clientSecret: connection.clientSecret,\n    method: connection.method,\n    grantType: connection.grantType,","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/knowledgeSources/sharepoint/connection.ts#L166-L202","documentation":"The auth config is an OAuth2 client-credentials config, but its token endpoint URL (authConfig.url) or clientId is empty. Both are required to obtain a bearer token from Microsoft Entra ID, so readConnection throws a 400 HTTPError before attempting any network call.","triggerScenarios":"Saving a client-credentials auth config without the token URL or without a client ID, then using it for SharePoint knowledge source operations.","commonSituations":"Incomplete datasource setup wizard; user left the token URL field blank (correct Entra endpoint is https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token); client ID omitted; config migrated and fields lost.","solutions":["Set authConfig.url to the Microsoft Entra token endpoint for your tenant.","Set authConfig.clientId to the application (client) ID of your Entra app registration.","Re-save the datasource auth config and verify both fields persist before retrying."],"exampleFix":"// before\n{ type: \"oauth2\", grantType: \"client_credentials\", clientId: \"\" }\n// after\n{ type: \"oauth2\", grantType: \"client_credentials\", url: \"https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/token\", clientId: \"<app-client-id>\", clientSecret: \"...\" }","handlingStrategy":"validation","validationCode":"if (!authConfig.url || !authConfig.clientId) {\n  throw new Error(\"OAuth2 auth config requires a token URL and client ID\")\n}\nawait fetchSharePointSitesByDatasourceAuthConfig(datasourceId, authConfigId)","typeGuard":"const hasOAuth2ConnectionFields = (\n  c: OAuth2RestAuthConfig\n): c is OAuth2RestAuthConfig & { url: string; clientId: string } =>\n  typeof c.url === \"string\" && c.url.length > 0 &&\n  typeof c.clientId === \"string\" && c.clientId.length > 0","tryCatchPattern":null,"preventionTips":["Require url and clientId fields when saving a client-credentials auth config in the UI.","Use the full Entra v2.0 token endpoint URL including tenant id.","Re-validate stored auth configs after migrations or imports."],"tags":["sharepoint","oauth2","missing-env-var","http-400"],"backgroundTag":"oauth-config-missing-fields","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}