@mvx/identity
Version:
identity is oidc for mvc, type-mvc is base on koa. Decorator, Ioc, AOP mvc framework on server.
62 lines (60 loc) • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalStrategy = void 0;
const tslib_1 = require("tslib");
const components_1 = require("@tsdi/components");
const Strategy_1 = require("./Strategy");
const results_1 = require("./results");
/**
* Local authenticate strategy
*
* @export
* @class LocalStrategy
* @extends {Strategy}
* @implements {AfterInit}
*/
let LocalStrategy = class LocalStrategy extends Strategy_1.Strategy {
async onAfterInit() {
if (!this.name) {
this.name = 'local';
}
if (!this.usernameField) {
this.usernameField = 'username';
}
if (!this.passwordField) {
this.passwordField = 'password';
}
}
async authenticate(ctx, options) {
let username = ctx.request.body[this.usernameField] || ctx.query[this.usernameField];
let password = ctx.request.body[this.passwordField] || ctx.query[this.passwordField];
let { user, info } = await this.verify(username, password, ctx);
if (!user) {
// TODO, not sure 401 is the correct meaning
return new results_1.FailResult(info, 401);
}
return new results_1.SuccessResult(options, user, info);
}
static ρAnn() {
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);
exports.LocalStrategy = LocalStrategy;
//# sourceMappingURL=../sourcemaps/passports/LocalStrategy.js.map