UNPKG

@mvx/identity

Version:

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

61 lines (59 loc) 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SessionStrategy = void 0; const Strategy_1 = require("./Strategy"); const results_1 = require("./results"); /** * session. * * @export * @class SessionStrategy * @extends {Strategy} */ class SessionStrategy extends Strategy_1.Strategy { /** * `SessionStrategy` constructor. * */ constructor() { super(); this.name = 'session'; } /** * 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. * */ async authenticate(ctx, options = {}) { if (!ctx.passport) { throw new Error('passport.initialize() middleware not in use'); } let su; if (ctx.session.passport) { su = ctx.session.passport.user; } if (su || su === 0) { // NOTE: Stream pausing is desirable in the case where later middleware is // listening for events emitted from request. For discussion on the // matter, refer to: https://github.com/jaredhanson/passport/pull/106 const user = await ctx.passport.deserializeUser(su, ctx); if (!user) { ctx.session.passport.user = undefined; return new results_1.PassResult(); } const property = ctx.passport.userProperty; ctx.state[property] = user; } return new results_1.PassResult(); } static ρAnn() { return { "name": "SessionStrategy" }; } } exports.SessionStrategy = SessionStrategy; //# sourceMappingURL=../sourcemaps/passports/SessionStrategy.js.map