@mvx/identity
Version:
identity is oidc for mvc, type-mvc is base on koa. Decorator, Ioc, AOP mvc framework on server.
60 lines (58 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthMiddleware = void 0;
const tslib_1 = require("tslib");
const ioc_1 = require("@tsdi/ioc");
const mvc_1 = require("@mvx/mvc");
const passports_1 = require("../passports");
require("../passports/IAuthenticator");
/**
* authentication middleware.
*
* @export
* @class AuthMiddleware
* @extends {CompositeMiddleware}
*/
let AuthMiddleware = class AuthMiddleware extends mvc_1.CompositeMiddleware {
constructor() {
super(...arguments);
this.hasInit = false;
}
getChecker() {
if (!this.checker) {
this.checker = this.getInjector().get(mvc_1.RouteChecker);
}
return this.checker;
}
async execute(ctx, next) {
if (!this.hasInit) {
await this.setup(ctx.mvcContext);
this.hasInit = true;
}
await super.execute(ctx);
ctx.passport = this.passport;
return await next();
}
async setup(context) {
var _a, _b;
let { passports } = context.getConfiguration();
let initOpt = (_b = (_a = passports.default) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : {};
this.use(this.passport.initialize(Object.assign({ userProperty: initOpt.userProperty || initOpt.assignProperty, rolesProperty: initOpt.rolesProperty }, passports.initialize)));
this.use(this.passport.session());
}
static ρAnn() {
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);
exports.AuthMiddleware = AuthMiddleware;
//# sourceMappingURL=../sourcemaps/middlewares/AuthMiddleware.js.map