Skip to main content
Glama
oauth-provider.ts1.95 kB
import { ProxyOAuthServerProvider } from '@modelcontextprotocol/sdk/server/auth/providers/proxyProvider.js'; import type { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js'; import logger from './logger.js'; import AuthManager from './auth.js'; export class MicrosoftOAuthProvider extends ProxyOAuthServerProvider { private authManager: AuthManager; constructor(authManager: AuthManager) { const tenantId = process.env.MS365_MCP_TENANT_ID || 'common'; const clientId = process.env.MS365_MCP_CLIENT_ID || '084a3e9f-a9f4-43f7-89f9-d229cf97853e'; super({ endpoints: { authorizationUrl: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/authorize`, tokenUrl: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/token`, revocationUrl: `https://login.microsoftonline.com/${tenantId}/oauth2/v2.0/logout`, }, verifyAccessToken: async (token: string): Promise<AuthInfo> => { try { const response = await fetch('https://graph.microsoft.com/v1.0/me', { headers: { Authorization: `Bearer ${token}`, }, }); if (response.ok) { const userData = await response.json(); logger.info(`OAuth token verified for user: ${userData.userPrincipalName}`); await authManager.setOAuthToken(token); return { token, clientId, scopes: [], }; } else { throw new Error(`Token verification failed: ${response.status}`); } } catch (error) { logger.error(`OAuth token verification error: ${error}`); throw error; } }, getClient: async (client_id: string) => { return { client_id, redirect_uris: ['http://localhost:3000/callback'], }; }, }); this.authManager = authManager; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Softeria/ms-365-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server