UNPKG

@mvx/identity

Version:

identity is oidc for mvc, type-mvc is base on koa. Decorator, Ioc, AOP mvc framework on server.

81 lines (79 loc) 3.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthMiddleware = void 0; var tslib_1 = require("tslib"); var ioc_1 = require("@tsdi/ioc"); var mvc_1 = require("@mvx/mvc"); var passports_1 = require("../passports"); require("../passports/IAuthenticator"); /** * authentication middleware. * * @export * @class AuthMiddleware * @extends {CompositeMiddleware} */ var AuthMiddleware = /** @class */ (function (_super) { tslib_1.__extends(AuthMiddleware, _super); function AuthMiddleware() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.hasInit = false; return _this; } AuthMiddleware.prototype.getChecker = function () { if (!this.checker) { this.checker = this.getInjector().get(mvc_1.RouteChecker); } return this.checker; }; AuthMiddleware.prototype.execute = function (ctx, next) { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: if (!!this.hasInit) return [3 /*break*/, 2]; return [4 /*yield*/, this.setup(ctx.mvcContext)]; case 1: _a.sent(); this.hasInit = true; _a.label = 2; case 2: return [4 /*yield*/, _super.prototype.execute.call(this, ctx)]; case 3: _a.sent(); ctx.passport = this.passport; return [4 /*yield*/, next()]; case 4: return [2 /*return*/, _a.sent()]; } }); }); }; AuthMiddleware.prototype.setup = function (context) { var _a, _b; return tslib_1.__awaiter(this, void 0, void 0, function () { var passports, initOpt; return tslib_1.__generator(this, function (_c) { passports = context.getConfiguration().passports; initOpt = (_b = (_a = passports.default) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : {}; this.use(this.passport.initialize(tslib_1.__assign({ userProperty: initOpt.userProperty || initOpt.assignProperty, rolesProperty: initOpt.rolesProperty }, passports.initialize))); this.use(this.passport.session()); return [2 /*return*/]; }); }); }; AuthMiddlewareAnn = function () { return { "name": "AuthMiddleware", "params": { "execute": ["ctx", "next"], "setup": ["context"] } }; }; tslib_1.__decorate([ ioc_1.Inject(passports_1.AuthenticatorToken), tslib_1.__metadata("design:type", Object) ], AuthMiddleware.prototype, "passport", void 0); AuthMiddleware = tslib_1.__decorate([ mvc_1.Middleware({ name: 'auth', before: mvc_1.MiddlewareTypes.View }) ], AuthMiddleware); return AuthMiddleware; }(mvc_1.CompositeMiddleware)); exports.AuthMiddleware = AuthMiddleware; //# sourceMappingURL=../sourcemaps/middlewares/AuthMiddleware.js.map