{"id":"7f4aee2e28c6c617","repo":"redis/node-redis","slug":"msal-client-id-and-msal-tenant-id-environment-vari-7f4aee","errorCode":null,"errorMessage":"MSAL_CLIENT_ID and MSAL_TENANT_ID environment variables must be set","messagePattern":"MSAL_CLIENT_ID and MSAL_TENANT_ID environment variables must be set","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/entraid/samples/interactive-browser/index.ts","lineNumber":30,"sourceCode":"\nconst app = express();\n\nconst sessionConfig = {\n  secret: process.env.SESSION_SECRET,\n  resave: false,\n  saveUninitialized: false,\n  cookie: {\n    secure: process.env.NODE_ENV === 'production', // Only use secure in production\n    httpOnly: true,\n    sameSite: 'lax',\n    maxAge: 3600000 // 1 hour\n  }\n} as const;\n\napp.use(session(sessionConfig));\n\nif (!process.env.MSAL_CLIENT_ID || !process.env.MSAL_TENANT_ID) {\n  throw new Error('MSAL_CLIENT_ID and MSAL_TENANT_ID environment variables must be set');\n}\n\n\napp.get('/login', async (req: Request, res: Response) => {\n  try {\n    // Create an instance of InteractiveBrowserCredential\n    const credential = new InteractiveBrowserCredential({\n      clientId: process.env.MSAL_CLIENT_ID!,\n      tenantId: process.env.MSAL_TENANT_ID!,\n      loginStyle: 'popup',\n      redirectUri: 'http://localhost:3000/redirect'\n    });\n\n    // Create Redis client using the EntraID credentials provider\n    const entraidCredentialsProvider = EntraIdCredentialsProviderFactory.createForDefaultAzureCredential({\n      credential,\n      scopes: ['user.read'],\n      tokenManagerConfig: DEFAULT_TOKEN_MANAGER_CONFIG","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/redis/node-redis/blob/bb5beb56578573910e2ee8f39681edc214c41398/packages/entraid/samples/interactive-browser/index.ts#L12-L48","documentation":"Startup guard in the interactive-browser sample (samples/interactive-browser/index.ts:29): InteractiveBrowserCredential and the Entra ID provider need MSAL_CLIENT_ID and MSAL_TENANT_ID. The sample throws at boot if either is unset, before constructing the credential.","triggerScenarios":"Running the interactive-browser sample without MSAL_CLIENT_ID and/or MSAL_TENANT_ID in the environment/.env.","commonSituations":"App registration not created; .env values left blank; env vars not exported in the run environment.","solutions":["Register an application in Entra ID; copy client ID and tenant ID.","Add `MSAL_CLIENT_ID` and `MSAL_TENANT_ID` to packages/entraid/.env.","Add the redirect URI (http://localhost:3000/redirect) to the app registration.","Re-run the sample after exporting both variables."],"exampleFix":"# .env\nMSAL_CLIENT_ID=11111111-2222-3333-4444-555555555555\nMSAL_TENANT_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee","handlingStrategy":"validation","validationCode":"function requireEntraEnv() {\n  const { MSAL_CLIENT_ID, MSAL_TENANT_ID } = process.env;\n  if (!MSAL_CLIENT_ID || !MSAL_TENANT_ID) {\n    throw new Error('Register an Entra ID app and set MSAL_CLIENT_ID and MSAL_TENANT_ID in .env');\n  }\n  return { MSAL_CLIENT_ID, MSAL_TENANT_ID };\n}","typeGuard":"const hasEntraAppEnv = (): boolean =>\n  /^[0-9a-f-]{36}$/i.test(process.env.MSAL_CLIENT_ID ?? '') &&\n  /^[0-9a-f-]{36}$/i.test(process.env.MSAL_TENANT_ID ?? '');","tryCatchPattern":null,"preventionTips":["Register the app in Entra ID and copy client/tenant IDs into .env.","Add the redirect URI to the app registration.","Validate env at startup in a single loader.","Document required vars in .env.example."],"tags":["configuration","environment","sample","entraid","azure"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}