outlook-mcp/auth/index.js
Seton Carmichael a7886b5b2b Initial commit: Outlook MCP Server v1.0.0
MCP server providing Microsoft Outlook integration via Graph API:
- Email: list, search, read, send, thread reconstruction
- Calendar: list, create, decline, cancel, delete events
- Folders: list, create, move emails
- Inbox rules: list, create, reorder
- MSAL device code flow auth with persistent token cache
- Test mode with mock data
- Comprehensive README with setup, config, and tool reference

20 MCP tools across 5 modules. Node.js >= 14. MIT license.
2026-06-21 19:39:31 -04:00

31 lines
859 B
JavaScript

/**
* 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<string>} - 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
};