UNPKG

@fusebit-int/microsoft-bot-framework-connector

Version:

Connector for the Microsoft Bot Framework

45 lines 1.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Service = void 0; const framework_1 = require("@fusebit-int/framework"); const superagent_1 = __importDefault(require("superagent")); const jwt_1 = require("./jwt"); class Service extends framework_1.Connector.Service { getEventsFromPayload(ctx) { return [ctx.req.body]; } getAuthIdFromEvent(ctx, event) { return event.recipient.id; } async validateWebhookEvent(ctx) { const { authorization } = ctx.req.headers; if (!authorization || !authorization.toLocaleLowerCase().startsWith('bearer ')) { ctx.throw(403, 'Invalid authorization'); } const token = authorization.split(' ')[1]; if (!token) { ctx.throw(403, 'Invalid authorization'); } const metadataUrl = 'https://login.botframework.com/v1/.well-known/openidconfiguration'; const metadataResponse = await superagent_1.default.get(metadataUrl); const { jwks_uri } = metadataResponse.body; try { await (0, jwt_1.verifyJwt)(token, jwks_uri); } catch (err) { ctx.throw(403, 'Invalid authorization provided'); } return true; } async initializationChallenge(ctx) { return false; } getWebhookEventType(event) { return event.type; } } exports.Service = Service; //# sourceMappingURL=Service.js.map