UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

57 lines 2.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateAuth = validateAuth; const basic_auth_1 = __importDefault(require("basic-auth")); const error_1 = require("./error"); async function validateAuth(context) { const authentication = context.getNodeParameter('authentication', 'none'); const req = context.getRequestObject(); const headers = context.getHeaderData(); if (authentication === 'none') { return; } else if (authentication === 'basicAuth') { let expectedAuth; try { expectedAuth = await context.getCredentials('httpBasicAuth'); } catch { } if (expectedAuth === undefined || !expectedAuth.user || !expectedAuth.password) { throw new error_1.ChatTriggerAuthorizationError(500, 'No authentication data defined on node!'); } const providedAuth = (0, basic_auth_1.default)(req); if (!providedAuth) throw new error_1.ChatTriggerAuthorizationError(401); if (providedAuth.name !== expectedAuth.user || providedAuth.pass !== expectedAuth.password) { throw new error_1.ChatTriggerAuthorizationError(403); } } else if (authentication === 'n8nUserAuth') { const webhookName = context.getWebhookName(); if (webhookName !== 'setup') { function getCookie(name) { const value = `; ${headers.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) { return parts.pop()?.split(';').shift(); } return ''; } const authCookie = getCookie('n8n-auth'); if (!authCookie) { throw new error_1.ChatTriggerAuthorizationError(401, 'User not authenticated!'); } try { await context.validateCookieAuth(authCookie); } catch { throw new error_1.ChatTriggerAuthorizationError(401, 'Invalid authentication token'); } } } return; } //# sourceMappingURL=GenericFunctions.js.map