UNPKG

@ryancardin/azuredevops-mcp-server

Version:

MCP server for Azure DevOps integration - provides seamless access to work items, repositories, projects, boards, and sprints

85 lines 3.59 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.EntraAuthHandler = void 0; const identity_1 = require("@azure/identity"); const azdev = __importStar(require("azure-devops-node-api")); class EntraAuthHandler { constructor() { this.scope = "499b84ac-1321-427f-aa17-267ca6975798/.default"; this.credential = new identity_1.DefaultAzureCredential(); } static async getInstance() { if (!EntraAuthHandler.instance) { EntraAuthHandler.instance = new EntraAuthHandler(); } await EntraAuthHandler.instance.ensureToken(); return EntraAuthHandler.instance; } isTokenExpired() { const currentTime = new Date().getTime(); // Check if the token is expired or will expire in the next 60 seconds return this.token.expiresOnTimestamp <= currentTime + 60000; } async ensureToken() { if (!this.token || this.isTokenExpired()) { this.token = await this.credential.getToken(this.scope); this.authHandler = azdev.getHandlerFromToken(this.token.token); } } prepareRequest(options) { if (this.authHandler) { this.authHandler.prepareRequest(options); } // If no authHandler, the request will be sent unauthenticated. // If it fails with 401, canHandleAuthentication and handleAuthentication will be invoked. } canHandleAuthentication(response) { if (this.authHandler) { return this.authHandler.canHandleAuthentication(response); } // If authHandler is not set, we can handle it if it's a 401 error // typically handled by token-based authentication. // This condition is standard in azure-devops-node-api handlers. return response.message.statusCode === 401 && (response.message.statusMessage || "").toLowerCase().indexOf("non-authoritative") === -1; } async handleAuthentication(httpClient, requestInfo, objs) { await this.ensureToken(); return this.authHandler.handleAuthentication(httpClient, requestInfo, objs); } } exports.EntraAuthHandler = EntraAuthHandler; //# sourceMappingURL=EntraAuthHandler.js.map