/** * Authentication module for Outlook MCP server */ const tokenManager = require('./token-manager'); const { authTools } = require('./tools'); /** * Ensures the user is authenticated and returns an access token * @param {boolean} forceNew - Whether to force a new authentication * @returns {Promise} - Access token * @throws {Error} - If authentication fails */ async function ensureAuthenticated(forceNew = false) { if (forceNew) { throw new Error('Authentication required'); } // MSAL's acquireTokenSilent handles both cache lookup and silent refresh automatically. const accessToken = await tokenManager.getAccessToken(); if (accessToken) { return accessToken; } throw new Error('Authentication required'); } module.exports = { tokenManager, authTools, ensureAuthenticated };