@mvx/identity
Version:
identity is oidc for mvc, type-mvc is base on koa. Decorator, Ioc, AOP mvc framework on server.
72 lines (70 loc) • 2.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SessionStrategy = void 0;
var tslib_1 = require("tslib");
var Strategy_1 = require("./Strategy");
var results_1 = require("./results");
/**
* session.
*
* @export
* @class SessionStrategy
* @extends {Strategy}
*/
var SessionStrategy = /** @class */ (function (_super) {
tslib_1.__extends(SessionStrategy, _super);
/**
* `SessionStrategy` constructor.
*
*/
function SessionStrategy() {
var _this = _super.call(this) || this;
_this.name = 'session';
return _this;
}
/**
* Authenticate request based on the current session state.
*
* The session authentication strategy uses the session to restore any login
* state across requests. If a login session has been established, `req.user`
* will be populated with the current user.
*
* This strategy is registered automatically by Passport.
*
*/
SessionStrategy.prototype.authenticate = function (ctx, options) {
if (options === void 0) { options = {}; }
return tslib_1.__awaiter(this, void 0, void 0, function () {
var su, user, property;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!ctx.passport) {
throw new Error('passport.initialize() middleware not in use');
}
if (ctx.session.passport) {
su = ctx.session.passport.user;
}
if (!(su || su === 0)) return [3 /*break*/, 2];
return [4 /*yield*/, ctx.passport.deserializeUser(su, ctx)];
case 1:
user = _a.sent();
if (!user) {
ctx.session.passport.user = undefined;
return [2 /*return*/, new results_1.PassResult()];
}
property = ctx.passport.userProperty;
ctx.state[property] = user;
_a.label = 2;
case 2: return [2 /*return*/, new results_1.PassResult()];
}
});
});
};
SessionStrategy.ρAnn = function () {
return { "name": "SessionStrategy" };
};
return SessionStrategy;
}(Strategy_1.Strategy));
exports.SessionStrategy = SessionStrategy;
//# sourceMappingURL=../sourcemaps/passports/SessionStrategy.js.map