{"record":{"id":"aec5fec95afff946","repo":"Budibase/budibase","slug":"no-microsoft-datasource-configuration-found","errorCode":null,"errorMessage":"No Microsoft datasource configuration found","messagePattern":"No Microsoft datasource configuration found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/server/src/api/controllers/ai/sharepointAuth.ts","lineNumber":20,"sourceCode":"import { DatasourceAuthCookie, UserCtx } from \"@budibase/types\"\n\nconst DEFAULT_SCOPE = env.RAG_SHAREPOINT_DEFAULT_SCOPE\nconst STATE_CACHE_TTL_SECONDS = 600\nconst MICROSOFT_PROVIDER = \"microsoft\"\nconst MICROSOFT_GRAPH_BASE = \"https://graph.microsoft.com/v1.0\"\nconst TOKEN_EXPIRY_BUFFER_SECONDS = 60\n\nexport const calculateBufferedTokenExpiry = (expiresInSeconds: number) => {\n  const bufferedTtlSeconds = Math.max(\n    expiresInSeconds - TOKEN_EXPIRY_BUFFER_SECONDS,\n    0\n  )\n  return Date.now() + bufferedTtlSeconds * 1000\n}\n\nconst getMicrosoftConfig = () => {\n  if (!env.MICROSOFT_CLIENT_ID || !env.MICROSOFT_CLIENT_SECRET) {\n    throw new Error(\"No Microsoft datasource configuration found\")\n  }\n  return {\n    clientId: env.MICROSOFT_CLIENT_ID,\n    clientSecret: env.MICROSOFT_CLIENT_SECRET,\n    tenantId: env.MICROSOFT_TENANT_ID || \"common\",\n  }\n}\n\nconst appendQueryParam = (path: string, key: string, value: string) => {\n  const base = \"http://localhost\"\n  const url = new URL(path, base)\n  url.searchParams.set(key, value)\n  const qs = url.searchParams.toString()\n  return `${url.pathname}${qs ? `?${qs}` : \"\"}`\n}\n\nexport async function startSharePointAuth(ctx: UserCtx<void, void>) {\n  const appId = String(ctx.query.appId || \"\").trim()","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/sharepointAuth.ts#L2-L38","documentation":"getMicrosoftConfig validates that MICROSOFT_CLIENT_ID and MICROSOFT_CLIENT_SECRET are set in the environment; if either is missing it throws this Error. The returned config also defaults MICROSOFT_TENANT_ID to 'common'.","triggerScenarios":"Any SharePoint OAuth flow (start or callback) executed on a server that lacks MICROSOFT_CLIENT_ID or MICROSOFT_CLIENT_SECRET env vars, including the OAuth callback path in completeSharePointAuth which calls getMicrosoftConfig to exchange the code.","commonSituations":"Fresh deployment without Microsoft credentials provisioned; self-hosted install missing env entries in .env; secrets configured for the worker but not the server (or vice versa); typo in env var name.","solutions":["Set MICROSOFT_CLIENT_ID and MICROSOFT_CLIENT_SECRET in the server's environment and restart.","Optionally set MICROSOFT_TENANT_ID (defaults to 'common' for multi-tenant apps).","Verify via deployment config/secrets manager that the vars are injected into the correct service container."],"exampleFix":"// before (env)\n# MICROSOFT_CLIENT_ID not set\n// after (env)\nMICROSOFT_CLIENT_ID=your-app-client-id\nMICROSOFT_CLIENT_SECRET=your-app-client-secret\nMICROSOFT_TENANT_ID=your-tenant-id","handlingStrategy":"validation","validationCode":"if (!process.env.MICROSOFT_CLIENT_ID || !process.env.MICROSOFT_CLIENT_SECRET) {\n  throw new Error('Set MICROSOFT_CLIENT_ID and MICROSOFT_CLIENT_SECRET before using SharePoint auth')\n}","typeGuard":"function microsoftEnvIsConfigured(env: typeof import('@budibase/backend-core').env): boolean {\n  return Boolean(env.MICROSOFT_CLIENT_ID && env.MICROSOFT_CLIENT_SECRET)\n}","tryCatchPattern":"try {\n  await startSharePointAuth(ctx)\n} catch (e) {\n  if (e.message === 'No Microsoft datasource configuration found') {\n    // surface a config-required message to the admin\n  } else throw e\n}","preventionTips":["Add a startup health check that fails fast when Microsoft env vars are missing.","Keep server and worker env configs in sync via a shared .env/secret template.","Document required MICROSOFT_* variables in deployment docs."],"tags":["env","configuration","oauth","microsoft","sharepoint"],"backgroundTag":"missing-env-var","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}