UNPKG

wcz-layout

Version:

1 lines 2.31 kB
{"version":3,"file":"msalServer-Ce9p7sTC.mjs","names":["createServerOnlyFn","ConfidentialClientApplication","scopes","definedScopes","ccaInstance","getCCA","Promise","createConfidentialClient","getAppToken","scopeKey","cca","defaultScopes","map","scope","lastSlash","lastIndexOf","baseUri","substring","uniqueScopes","Set","result","acquireTokenByClientCredential","Error","accessToken"],"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,IAAII,cAAoD;AACxD,MAAMC,SAAS,YAAoD;CACjE,IAAI,CAACD,aAAa;EAChB,MAAM,EAAEG,6BAA6B,MAAM,OAAO;EAClDH,cAAcG,yBAAyB;CACzC;CACA,OAAOH;AACT;;;;;AAMA,MAAaI,cAAcR,mBACzB,OAAOS,aAA0D;CAC/D,MAAMC,MAAM,MAAML,OAAO;CAEzB,MAAMM,gBADSR,OAAcM,SACD,CAACG,KAAKC,UAAU;EAC1C,MAAMC,YAAYD,MAAME,YAAY,GAAG;EAEvC,OAAO,GADSF,MAAMI,UAAU,GAAGH,SACzBE,EAAO;CACnB,CAAC;CACD,MAAME,eAAe,CAAC,GAAG,IAAIC,IAAIR,aAAa,CAAC;CAC/C,MAAMS,SAAS,MAAMV,IAAIW,+BAA+B,EAAEnB,QAAQgB,aAAa,CAAC;CAChF,IAAI,CAACE,QAAQ,MAAM,IAAIE,MAAM,6BAA6B;CAC1D,OAAOF,OAAOG;AAChB,CACF"}