UNPKG

n8n-nodes-smartgent

Version:

SmartGent custom nodes for n8n - AI-powered automation and intelligent workflow integrations including LiteLLM chat completions, SharePoint file monitoring, and enterprise search

46 lines 1.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGraphAccessTokenFromEnv = exports.getGraphAccessToken = void 0; const axios_1 = __importDefault(require("axios")); const qs_1 = __importDefault(require("qs")); const getGraphAccessToken = async (options) => { const { tokenEndpoint, clientId, clientSecret, scope = 'https://graph.microsoft.com/.default', grantType = 'client_credentials' } = options; const data = { grant_type: grantType, client_id: clientId, scope, client_secret: clientSecret, }; const requestOptions = { method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, data: qs_1.default.stringify(data), url: tokenEndpoint }; try { const response = await (0, axios_1.default)(requestOptions); return response.data.access_token; } catch (error) { throw new Error(`Failed to get Graph access token: ${error}`); } }; exports.getGraphAccessToken = getGraphAccessToken; const getGraphAccessTokenFromEnv = async () => { const tokenEndpoint = process.env.SC_TOKEN_ENDPOINT; const clientId = process.env.SC_CLIENT_ID; const clientSecret = process.env.SC_CLIENT_SECRET; if (!tokenEndpoint || !clientId || !clientSecret) { throw new Error('Missing required environment variables: SC_TOKEN_ENDPOINT, SC_CLIENT_ID, SC_CLIENT_SECRET'); } return (0, exports.getGraphAccessToken)({ tokenEndpoint, clientId, clientSecret }); }; exports.getGraphAccessTokenFromEnv = getGraphAccessTokenFromEnv; //# sourceMappingURL=graphAuth.js.map