wcz-layout
Version:
1 lines • 1.94 kB
Source Map (JSON)
{"version":3,"file":"msalServer-DLwA7_ta.mjs","names":[],"sources":["../src/lib/auth/msalServer.ts"],"sourcesContent":["import { createServerOnlyFn } from \"@tanstack/react-start\";\nimport type { ConfidentialClientApplication } from \"@azure/msal-node\";\nimport { scopes as definedScopes } from \"virtual:wcz-layout\";\n\nlet ccaInstance: ConfidentialClientApplication | null = null;\nconst getCCA = async (): Promise<ConfidentialClientApplication> => {\n if (!ccaInstance) {\n const { createConfidentialClient } = await import(\"./entra\");\n ccaInstance = createConfidentialClient();\n }\n return ccaInstance;\n};\n\n/**\n * Client Credentials flow: Get app-only token (no user context)\n * Use when: Background jobs, scheduled tasks, service-to-service calls\n */\nexport const getAppToken = createServerOnlyFn(\n async (scopeKey: keyof typeof definedScopes): Promise<string> => {\n const cca = await getCCA();\n const scopes = definedScopes[scopeKey];\n const defaultScopes = scopes.map((scope) => {\n const lastSlash = scope.lastIndexOf(\"/\");\n const baseUri = scope.substring(0, lastSlash);\n return `${baseUri}/.default`;\n });\n const uniqueScopes = [...new Set(defaultScopes)];\n const result = await cca.acquireTokenByClientCredential({ scopes: uniqueScopes });\n if (!result) throw new Error(\"Failed to acquire app token\");\n return result.accessToken;\n },\n);\n"],"mappings":";;;AAIA,IAAI,cAAoD;AACxD,MAAM,SAAS,YAAoD;CACjE,IAAI,CAAC,aAAa;EAChB,MAAM,EAAE,6BAA6B,MAAM,OAAO;EAClD,cAAc,yBAAyB;CACzC;CACA,OAAO;AACT;;;;;AAMA,MAAa,cAAc,mBACzB,OAAO,aAA0D;CAC/D,MAAM,MAAM,MAAM,OAAO;CAEzB,MAAM,gBADS,OAAc,SACD,CAAC,KAAK,UAAU;EAC1C,MAAM,YAAY,MAAM,YAAY,GAAG;EAEvC,OAAO,GADS,MAAM,UAAU,GAAG,SACzB,EAAO;CACnB,CAAC;CACD,MAAM,eAAe,CAAC,GAAG,IAAI,IAAI,aAAa,CAAC;CAC/C,MAAM,SAAS,MAAM,IAAI,+BAA+B,EAAE,QAAQ,aAAa,CAAC;CAChF,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,6BAA6B;CAC1D,OAAO,OAAO;AAChB,CACF"}