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.
31 lines
859 B
JavaScript
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
|
|
};
|