redis/node-redis · error · Error
MSAL_CLIENT_ID and MSAL_TENANT_ID environment variables must
Error message
MSAL_CLIENT_ID and MSAL_TENANT_ID environment variables must be set
What it means
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.
Source
Thrown at packages/entraid/samples/interactive-browser/index.ts:30
const app = express();
const sessionConfig = {
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV === 'production', // Only use secure in production
httpOnly: true,
sameSite: 'lax',
maxAge: 3600000 // 1 hour
}
} as const;
app.use(session(sessionConfig));
if (!process.env.MSAL_CLIENT_ID || !process.env.MSAL_TENANT_ID) {
throw new Error('MSAL_CLIENT_ID and MSAL_TENANT_ID environment variables must be set');
}
app.get('/login', async (req: Request, res: Response) => {
try {
// Create an instance of InteractiveBrowserCredential
const credential = new InteractiveBrowserCredential({
clientId: process.env.MSAL_CLIENT_ID!,
tenantId: process.env.MSAL_TENANT_ID!,
loginStyle: 'popup',
redirectUri: 'http://localhost:3000/redirect'
});
// Create Redis client using the EntraID credentials provider
const entraidCredentialsProvider = EntraIdCredentialsProviderFactory.createForDefaultAzureCredential({
credential,
scopes: ['user.read'],
tokenManagerConfig: DEFAULT_TOKEN_MANAGER_CONFIGView on GitHub (pinned to bb5beb5657)
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.
Example fix
# .env MSAL_CLIENT_ID=11111111-2222-3333-4444-555555555555 MSAL_TENANT_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
Defensive patterns
Strategy: validation
Validate before calling
function requireEntraEnv() {
const { MSAL_CLIENT_ID, MSAL_TENANT_ID } = process.env;
if (!MSAL_CLIENT_ID || !MSAL_TENANT_ID) {
throw new Error('Register an Entra ID app and set MSAL_CLIENT_ID and MSAL_TENANT_ID in .env');
}
return { MSAL_CLIENT_ID, MSAL_TENANT_ID };
} Type guard
const hasEntraAppEnv = (): boolean =>
/^[0-9a-f-]{36}$/i.test(process.env.MSAL_CLIENT_ID ?? '') &&
/^[0-9a-f-]{36}$/i.test(process.env.MSAL_TENANT_ID ?? ''); Prevention
- 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.
When it happens
Trigger: Running the interactive-browser sample without MSAL_CLIENT_ID and/or MSAL_TENANT_ID in the environment/.env.
Common situations: App registration not created; .env values left blank; env vars not exported in the run environment.
Related errors
- MSAL_CLIENT_ID and MSAL_TENANT_ID environment variables must
- SESSION_SECRET environment variable must be set
- SESSION_SECRET environment variable must be set
- Invalid authority configuration
- Invalid token response
AI-assisted analysis of redis/node-redis@bb5beb5657 (2026-08-03).
Data as JSON: /data/errors/7f4aee2e28c6c617.json.
Report an issue: GitHub.