UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.

31 lines 1.22 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const authentication_required_1 = __importDefault(require("../types/authentication-required")); function ossAuthHook(app, baseUriPath) { const generateAuthResponse = async () => new authentication_required_1.default({ type: 'password', path: `${baseUriPath}/auth/simple/login`, message: 'You must sign in order to use Unleash', }); app.use(`${baseUriPath}/api`, async (req, res, next) => { if (req.session && req.session.user) { req.user = req.session.user; return next(); } if (req.user) { return next(); } if (req.header('authorization')) { // API clients should get 401 without body return res.sendStatus(401); } // Admin UI users should get auth-response const authRequired = await generateAuthResponse(); return res.status(401).json(authRequired); }); } exports.default = ossAuthHook; //# sourceMappingURL=oss-authentication.js.map