@mvx/identity
Version:
identity is oidc for mvc, type-mvc is base on koa. Decorator, Ioc, AOP mvc framework on server.
82 lines (80 loc) • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalStrategy = void 0;
var tslib_1 = require("tslib");
var components_1 = require("@tsdi/components");
var Strategy_1 = require("./Strategy");
var results_1 = require("./results");
/**
* Local authenticate strategy
*
* @export
* @class LocalStrategy
* @extends {Strategy}
* @implements {AfterInit}
*/
var LocalStrategy = /** @class */ (function (_super) {
tslib_1.__extends(LocalStrategy, _super);
function LocalStrategy() {
return _super !== null && _super.apply(this, arguments) || this;
}
LocalStrategy.prototype.onAfterInit = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
if (!this.name) {
this.name = 'local';
}
if (!this.usernameField) {
this.usernameField = 'username';
}
if (!this.passwordField) {
this.passwordField = 'password';
}
return [2 /*return*/];
});
});
};
LocalStrategy.prototype.authenticate = function (ctx, options) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var username, password, _a, user, info;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
username = ctx.request.body[this.usernameField] || ctx.query[this.usernameField];
password = ctx.request.body[this.passwordField] || ctx.query[this.passwordField];
return [4 /*yield*/, this.verify(username, password, ctx)];
case 1:
_a = _b.sent(), user = _a.user, info = _a.info;
if (!user) {
// TODO, not sure 401 is the correct meaning
return [2 /*return*/, new results_1.FailResult(info, 401)];
}
return [2 /*return*/, new results_1.SuccessResult(options, user, info)];
}
});
});
};
LocalStrategy.ρAnn = function () {
return { "name": "LocalStrategy", "params": { "authenticate": ["ctx", "options"] } };
};
tslib_1.__decorate([
components_1.Input(),
tslib_1.__metadata("design:type", Function)
], LocalStrategy.prototype, "verify", void 0);
tslib_1.__decorate([
components_1.Input(),
tslib_1.__metadata("design:type", Object)
], LocalStrategy.prototype, "usernameField", void 0);
tslib_1.__decorate([
components_1.Input(),
tslib_1.__metadata("design:type", Object)
], LocalStrategy.prototype, "passwordField", void 0);
LocalStrategy = tslib_1.__decorate([
components_1.Component({
selector: 'local'
})
], LocalStrategy);
return LocalStrategy;
}(Strategy_1.Strategy));
exports.LocalStrategy = LocalStrategy;
//# sourceMappingURL=../sourcemaps/passports/LocalStrategy.js.map