@spinajs/rbac-http-user 2.0.473 → 2.0.474
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/controllers/ActiveRoleController.d.ts +41 -0
- package/lib/cjs/controllers/ActiveRoleController.d.ts.map +1 -0
- package/lib/cjs/controllers/ActiveRoleController.js +135 -0
- package/lib/cjs/controllers/ActiveRoleController.js.map +1 -0
- package/lib/cjs/controllers/ImpersonationController.d.ts +72 -0
- package/lib/cjs/controllers/ImpersonationController.d.ts.map +1 -0
- package/lib/cjs/controllers/ImpersonationController.js +277 -0
- package/lib/cjs/controllers/ImpersonationController.js.map +1 -0
- package/lib/cjs/controllers/LoginController.d.ts +27 -4
- package/lib/cjs/controllers/LoginController.d.ts.map +1 -1
- package/lib/cjs/controllers/LoginController.js +46 -27
- package/lib/cjs/controllers/LoginController.js.map +1 -1
- package/lib/cjs/dto/impersonate-dto.d.ts +24 -0
- package/lib/cjs/dto/impersonate-dto.d.ts.map +1 -0
- package/lib/cjs/dto/impersonate-dto.js +34 -0
- package/lib/cjs/dto/impersonate-dto.js.map +1 -0
- package/lib/cjs/dto/switchRole-dto.d.ts +24 -0
- package/lib/cjs/dto/switchRole-dto.d.ts.map +1 -0
- package/lib/cjs/dto/switchRole-dto.js +34 -0
- package/lib/cjs/dto/switchRole-dto.js.map +1 -0
- package/lib/cjs/handlers/DefaultLogoutHandler.d.ts +14 -0
- package/lib/cjs/handlers/DefaultLogoutHandler.d.ts.map +1 -0
- package/lib/cjs/handlers/DefaultLogoutHandler.js +61 -0
- package/lib/cjs/handlers/DefaultLogoutHandler.js.map +1 -0
- package/lib/cjs/handlers/ImpersonationLogoutHandler.d.ts +18 -0
- package/lib/cjs/handlers/ImpersonationLogoutHandler.d.ts.map +1 -0
- package/lib/cjs/handlers/ImpersonationLogoutHandler.js +66 -0
- package/lib/cjs/handlers/ImpersonationLogoutHandler.js.map +1 -0
- package/lib/cjs/index.d.ts +5 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +5 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/logout.d.ts +51 -0
- package/lib/cjs/logout.d.ts.map +1 -0
- package/lib/cjs/logout.js +29 -0
- package/lib/cjs/logout.js.map +1 -0
- package/lib/mjs/controllers/ActiveRoleController.d.ts +41 -0
- package/lib/mjs/controllers/ActiveRoleController.d.ts.map +1 -0
- package/lib/mjs/controllers/ActiveRoleController.js +132 -0
- package/lib/mjs/controllers/ActiveRoleController.js.map +1 -0
- package/lib/mjs/controllers/ImpersonationController.d.ts +72 -0
- package/lib/mjs/controllers/ImpersonationController.d.ts.map +1 -0
- package/lib/mjs/controllers/ImpersonationController.js +274 -0
- package/lib/mjs/controllers/ImpersonationController.js.map +1 -0
- package/lib/mjs/controllers/LoginController.d.ts +27 -4
- package/lib/mjs/controllers/LoginController.d.ts.map +1 -1
- package/lib/mjs/controllers/LoginController.js +48 -29
- package/lib/mjs/controllers/LoginController.js.map +1 -1
- package/lib/mjs/dto/impersonate-dto.d.ts +24 -0
- package/lib/mjs/dto/impersonate-dto.d.ts.map +1 -0
- package/lib/mjs/dto/impersonate-dto.js +31 -0
- package/lib/mjs/dto/impersonate-dto.js.map +1 -0
- package/lib/mjs/dto/switchRole-dto.d.ts +24 -0
- package/lib/mjs/dto/switchRole-dto.d.ts.map +1 -0
- package/lib/mjs/dto/switchRole-dto.js +31 -0
- package/lib/mjs/dto/switchRole-dto.js.map +1 -0
- package/lib/mjs/handlers/DefaultLogoutHandler.d.ts +14 -0
- package/lib/mjs/handlers/DefaultLogoutHandler.d.ts.map +1 -0
- package/lib/mjs/handlers/DefaultLogoutHandler.js +58 -0
- package/lib/mjs/handlers/DefaultLogoutHandler.js.map +1 -0
- package/lib/mjs/handlers/ImpersonationLogoutHandler.d.ts +18 -0
- package/lib/mjs/handlers/ImpersonationLogoutHandler.d.ts.map +1 -0
- package/lib/mjs/handlers/ImpersonationLogoutHandler.js +63 -0
- package/lib/mjs/handlers/ImpersonationLogoutHandler.js.map +1 -0
- package/lib/mjs/index.d.ts +5 -0
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +5 -0
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/logout.d.ts +51 -0
- package/lib/mjs/logout.d.ts.map +1 -0
- package/lib/mjs/logout.js +25 -0
- package/lib/mjs/logout.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +11 -11
|
@@ -20,6 +20,7 @@ const di_1 = require("@spinajs/di");
|
|
|
20
20
|
const configuration_1 = require("@spinajs/configuration");
|
|
21
21
|
const rbac_http_1 = require("@spinajs/rbac-http");
|
|
22
22
|
const rbac_2 = require("@spinajs/rbac");
|
|
23
|
+
const logout_js_1 = require("../logout.js");
|
|
23
24
|
/**
|
|
24
25
|
* Authentication endpoints.
|
|
25
26
|
* Handles user login, logout, and current-session inspection.
|
|
@@ -63,6 +64,12 @@ let LoginController = class LoginController extends http_1.BaseController {
|
|
|
63
64
|
];
|
|
64
65
|
let result;
|
|
65
66
|
session.Data.set('User', user.Uuid);
|
|
67
|
+
// Default active role = first role from the user's role list.
|
|
68
|
+
// Users with multiple roles can later switch via /auth/active-role.
|
|
69
|
+
const activeRole = user.Role?.[0];
|
|
70
|
+
if (activeRole) {
|
|
71
|
+
session.Data.set('ActiveRole', activeRole);
|
|
72
|
+
}
|
|
66
73
|
// we have two states for user
|
|
67
74
|
// LOGGED - when user use proper login/password and session is created
|
|
68
75
|
// AUTHORIZED - when user is atuhenticated eg. by 2fa check. If 2fa is disabled
|
|
@@ -90,12 +97,12 @@ let LoginController = class LoginController extends http_1.BaseController {
|
|
|
90
97
|
else {
|
|
91
98
|
session.Data.set('Authorized', true);
|
|
92
99
|
const grants = this.AC.getGrants();
|
|
93
|
-
const
|
|
94
|
-
const combinedGrants = Object.assign({}, ...userGrants);
|
|
100
|
+
const combinedGrants = activeRole ? (0, rbac_1._unwindGrants)(activeRole, grants) : {};
|
|
95
101
|
// dehydrateWithRelations({ dateTimeFormat: 'iso' }) converts DateTime to ISO strings
|
|
96
102
|
// at runtime — the ORM types don't reflect the dateTimeFormat option in generics
|
|
97
103
|
result = {
|
|
98
104
|
...user.dehydrateWithRelations({ dateTimeFormat: "iso" }),
|
|
105
|
+
ActiveRole: activeRole,
|
|
99
106
|
Grants: combinedGrants,
|
|
100
107
|
};
|
|
101
108
|
}
|
|
@@ -120,43 +127,52 @@ let LoginController = class LoginController extends http_1.BaseController {
|
|
|
120
127
|
/**
|
|
121
128
|
* Logout
|
|
122
129
|
* Destroys the current session identified by the `ssid` cookie and clears the cookie on the client.
|
|
130
|
+
* If an impersonation is active, the session is NOT destroyed — instead the
|
|
131
|
+
* impersonation is ended and the original user resumes their session.
|
|
123
132
|
* Requires the user to be logged in (session exists), but full authorization (2FA) is not required.
|
|
124
133
|
* @security cookieAuth
|
|
125
134
|
* @response 401 No active session
|
|
126
135
|
*/
|
|
127
|
-
async logout(ssid) {
|
|
136
|
+
async logout(ssid, session, user) {
|
|
128
137
|
if (!ssid) {
|
|
129
138
|
return new http_1.Ok();
|
|
130
139
|
}
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
}
|
|
140
|
+
// Delegate to the registered LogoutHandler chain. Each handler decides
|
|
141
|
+
// whether to take ownership of the response (returns non-null) or defer
|
|
142
|
+
// to the next handler. Built-ins:
|
|
143
|
+
// - ImpersonationLogoutHandler (priority 10): reverts an active
|
|
144
|
+
// impersonation and keeps the session alive.
|
|
145
|
+
// - DefaultLogoutHandler (priority 999): destroys the session and clears
|
|
146
|
+
// the ssid cookie.
|
|
147
|
+
// Apps can register additional handlers via @Injectable(LogoutHandler).
|
|
148
|
+
const handlers = await di_1.DI.resolve(Array.ofType(logout_js_1.LogoutHandler));
|
|
149
|
+
const sorted = [...handlers].sort((a, b) => a.Priority - b.Priority);
|
|
150
|
+
const ctx = { Ssid: ssid, Session: session, User: user };
|
|
151
|
+
for (const handler of sorted) {
|
|
152
|
+
const result = await handler.handle(ctx);
|
|
153
|
+
if (result) {
|
|
154
|
+
return new http_1.Ok(result.Body ?? null, { Coockies: result.Cookies ?? [] });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// No handler claimed the request — should not happen as long as the
|
|
158
|
+
// default handler is registered, but return a clean response anyway.
|
|
159
|
+
return new http_1.Ok();
|
|
148
160
|
}
|
|
149
161
|
/**
|
|
150
162
|
* Get current user
|
|
151
|
-
* Returns the user object associated with the current session
|
|
163
|
+
* Returns the user object associated with the current session along with the
|
|
164
|
+
* currently active role and the full list of roles the user may switch to.
|
|
152
165
|
* Requires the user to be logged in (session exists), but full authorization (2FA) is not required.
|
|
153
166
|
* @security cookieAuth
|
|
154
|
-
* @returns {
|
|
167
|
+
* @returns {User} User data from the current session
|
|
155
168
|
* @response 401 No active session
|
|
156
169
|
*/
|
|
157
|
-
async whoami(User) {
|
|
158
|
-
|
|
159
|
-
|
|
170
|
+
async whoami(User, ActiveRole) {
|
|
171
|
+
return new http_1.Ok({
|
|
172
|
+
...User.dehydrateWithRelations({ dateTimeFormat: 'iso' }),
|
|
173
|
+
ActiveRole: ActiveRole ?? User.Role?.[0],
|
|
174
|
+
AvailableRoles: User.Role ?? [],
|
|
175
|
+
});
|
|
160
176
|
}
|
|
161
177
|
};
|
|
162
178
|
exports.LoginController = LoginController;
|
|
@@ -211,16 +227,19 @@ __decorate([
|
|
|
211
227
|
(0, http_1.Get)(),
|
|
212
228
|
(0, http_1.Policy)(rbac_http_1.LoggedPolicy),
|
|
213
229
|
__param(0, (0, http_1.Cookie)(true)),
|
|
230
|
+
__param(1, (0, rbac_http_1.Session)()),
|
|
231
|
+
__param(2, (0, rbac_http_1.User)()),
|
|
214
232
|
__metadata("design:type", Function),
|
|
215
|
-
__metadata("design:paramtypes", [String]),
|
|
233
|
+
__metadata("design:paramtypes", [String, Object, rbac_2.User]),
|
|
216
234
|
__metadata("design:returntype", Promise)
|
|
217
235
|
], LoginController.prototype, "logout", null);
|
|
218
236
|
__decorate([
|
|
219
237
|
(0, http_1.Get)(),
|
|
220
238
|
(0, http_1.Policy)(rbac_http_1.LoggedPolicy),
|
|
221
239
|
__param(0, (0, rbac_http_1.User)()),
|
|
240
|
+
__param(1, (0, rbac_http_1.FromSession)()),
|
|
222
241
|
__metadata("design:type", Function),
|
|
223
|
-
__metadata("design:paramtypes", [rbac_2.User]),
|
|
242
|
+
__metadata("design:paramtypes", [rbac_2.User, String]),
|
|
224
243
|
__metadata("design:returntype", Promise)
|
|
225
244
|
], LoginController.prototype, "whoami", null);
|
|
226
245
|
exports.LoginController = LoginController = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoginController.js","sourceRoot":"","sources":["../../../src/controllers/LoginController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8DAAuD;AACvD,wCAA4G;AAC5G,wCAAgH;AAChH,
|
|
1
|
+
{"version":3,"file":"LoginController.js","sourceRoot":"","sources":["../../../src/controllers/LoginController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,8DAAuD;AACvD,wCAA4G;AAC5G,wCAAgH;AAChH,oCAA6C;AAC7C,0DAAkF;AAElF,kDAAkJ;AAClJ,wCAAqC;AAErC,4CAA6D;AAG7D;;;;;GAKG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,qBAAc;IAgCjD;;;;;;;;;OASG;IAEU,AAAN,KAAK,CAAC,KAAK,CAAiB,MAAY,EAAgB,IAAY,EAAU,WAAyB;QAC5G,IAAI,CAAC;YAEH,0DAA0D;YAC1D,2BAA2B;YAC3B,IAAI,MAAM,IAAI,IAAI,E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AU,EAAC,oBAAa,CAAC;8BACZ,oBAAa;2CAAC;AAaf;IADZ,IAAA,WAAI,GAAE;IACa,WAAA,IAAA,gBAAY,GAAE,CAAA;IAAgB,WAAA,IAAA,aAAM,EAAC,IAAI,CAAC,CAAA;IAAgB,WAAA,IAAA,WAAI,GAAE,CAAA;;qCAAzC,WAAI,UAAmD,+BAAY;;4CA6G7G;AAaY;IAFZ,IAAA,UAAG,GAAE;IACL,IAAA,aAAM,EAAC,wBAAY,CAAC;IACA,WAAA,IAAA,aAAM,EAAC,IAAI,CAAC,CAAA;IAAgB,WAAA,IAAA,mBAAe,GAAE,CAAA;IAAqB,WAAA,IAAA,gBAAY,GAAE,CAAA;;qDAAO,WAAI;;6CA2B/G;AAaY;IAFZ,IAAA,UAAG,GAAE;IACL,IAAA,aAAM,EAAC,wBAAY,CAAC;IACA,WAAA,IAAA,gBAAY,GAAE,CAAA;IAAc,WAAA,IAAA,uBAAW,GAAE,CAAA;;qCAApB,WAAI;;6CAO7C;0BApNU,eAAe;IAD3B,IAAA,eAAQ,EAAC,MAAM,CAAC;GACJ,eAAe,CAqN3B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const ImpersonateDtoSchema: {
|
|
2
|
+
$schema: string;
|
|
3
|
+
title: string;
|
|
4
|
+
type: string;
|
|
5
|
+
properties: {
|
|
6
|
+
TargetUuid: {
|
|
7
|
+
type: string;
|
|
8
|
+
format: string;
|
|
9
|
+
description: string;
|
|
10
|
+
};
|
|
11
|
+
Password: {
|
|
12
|
+
type: string;
|
|
13
|
+
maxLength: number;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
required: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare class ImpersonateDto {
|
|
20
|
+
TargetUuid: string;
|
|
21
|
+
Password?: string;
|
|
22
|
+
constructor(data: any);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=impersonate-dto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impersonate-dto.d.ts","sourceRoot":"","sources":["../../../src/dto/impersonate-dto.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;CAShC,CAAC;AAEF,qBACa,cAAc;IAClB,UAAU,EAAE,MAAM,CAAC;IAEnB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEb,IAAI,EAAE,GAAG;CAGtB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ImpersonateDto = exports.ImpersonateDtoSchema = void 0;
|
|
13
|
+
const validation_1 = require("@spinajs/validation");
|
|
14
|
+
exports.ImpersonateDtoSchema = {
|
|
15
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
16
|
+
title: 'Impersonate DTO',
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
TargetUuid: { type: 'string', format: 'uuid', description: 'UUID of the user to impersonate' },
|
|
20
|
+
Password: { type: 'string', maxLength: 32, description: 'Impersonator password (required when rbac.impersonation.requirePassword is true)' },
|
|
21
|
+
},
|
|
22
|
+
required: ['TargetUuid'],
|
|
23
|
+
};
|
|
24
|
+
let ImpersonateDto = class ImpersonateDto {
|
|
25
|
+
constructor(data) {
|
|
26
|
+
Object.assign(this, data);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.ImpersonateDto = ImpersonateDto;
|
|
30
|
+
exports.ImpersonateDto = ImpersonateDto = __decorate([
|
|
31
|
+
(0, validation_1.Schema)(exports.ImpersonateDtoSchema),
|
|
32
|
+
__metadata("design:paramtypes", [Object])
|
|
33
|
+
], ImpersonateDto);
|
|
34
|
+
//# sourceMappingURL=impersonate-dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impersonate-dto.js","sourceRoot":"","sources":["../../../src/dto/impersonate-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,oBAAoB,GAAG;IAClC,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,iBAAiB;IACxB,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,iCAAiC,EAAE;QAC9F,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,WAAW,EAAE,kFAAkF,EAAE;KAC7I;IACD,QAAQ,EAAE,CAAC,YAAY,CAAC;CACzB,CAAC;AAGK,IAAM,cAAc,GAApB,MAAM,cAAc;IAKzB,YAAY,IAAS;QACnB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AARY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAM,EAAC,4BAAoB,CAAC;;GAChB,cAAc,CAQ1B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const SwitchRoleDtoSchema: {
|
|
2
|
+
$schema: string;
|
|
3
|
+
title: string;
|
|
4
|
+
type: string;
|
|
5
|
+
properties: {
|
|
6
|
+
Role: {
|
|
7
|
+
type: string;
|
|
8
|
+
minLength: number;
|
|
9
|
+
description: string;
|
|
10
|
+
};
|
|
11
|
+
Password: {
|
|
12
|
+
type: string;
|
|
13
|
+
maxLength: number;
|
|
14
|
+
description: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
required: string[];
|
|
18
|
+
};
|
|
19
|
+
export declare class SwitchRoleDto {
|
|
20
|
+
Role: string;
|
|
21
|
+
Password?: string;
|
|
22
|
+
constructor(data: any);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=switchRole-dto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchRole-dto.d.ts","sourceRoot":"","sources":["../../../src/dto/switchRole-dto.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;CAS/B,CAAC;AAEF,qBACa,aAAa;IACjB,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEb,IAAI,EAAE,GAAG;CAGtB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SwitchRoleDto = exports.SwitchRoleDtoSchema = void 0;
|
|
13
|
+
const validation_1 = require("@spinajs/validation");
|
|
14
|
+
exports.SwitchRoleDtoSchema = {
|
|
15
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
16
|
+
title: 'Switch active role DTO',
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
Role: { type: 'string', minLength: 1, description: 'Role to activate. Must be one of the user\'s assigned roles.' },
|
|
20
|
+
Password: { type: 'string', maxLength: 32, description: 'User password. Required when activating roles listed in rbac.roleSwitch.requirePassword.' },
|
|
21
|
+
},
|
|
22
|
+
required: ['Role'],
|
|
23
|
+
};
|
|
24
|
+
let SwitchRoleDto = class SwitchRoleDto {
|
|
25
|
+
constructor(data) {
|
|
26
|
+
Object.assign(this, data);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.SwitchRoleDto = SwitchRoleDto;
|
|
30
|
+
exports.SwitchRoleDto = SwitchRoleDto = __decorate([
|
|
31
|
+
(0, validation_1.Schema)(exports.SwitchRoleDtoSchema),
|
|
32
|
+
__metadata("design:paramtypes", [Object])
|
|
33
|
+
], SwitchRoleDto);
|
|
34
|
+
//# sourceMappingURL=switchRole-dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchRole-dto.js","sourceRoot":"","sources":["../../../src/dto/switchRole-dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA6C;AAEhC,QAAA,mBAAmB,GAAG;IACjC,OAAO,EAAE,yCAAyC;IAClD,KAAK,EAAE,wBAAwB;IAC/B,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE,WAAW,EAAE,8DAA8D,EAAE;QACnH,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,WAAW,EAAE,0FAA0F,EAAE;KACrJ;IACD,QAAQ,EAAE,CAAC,MAAM,CAAC;CACnB,CAAC;AAGK,IAAM,aAAa,GAAnB,MAAM,aAAa;IAKxB,YAAY,IAAS;QACnB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AARY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAM,EAAC,2BAAmB,CAAC;;GACf,aAAa,CAQzB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SessionProvider } from '@spinajs/rbac';
|
|
2
|
+
import { LogoutHandler, ILogoutContext, ILogoutResult } from '../logout.js';
|
|
3
|
+
/**
|
|
4
|
+
* Default logout handler: deletes the session and clears the ssid cookie.
|
|
5
|
+
* Runs last (priority 999) so any earlier handler can short-circuit (e.g.
|
|
6
|
+
* the impersonation revert handler) before the session is destroyed.
|
|
7
|
+
*/
|
|
8
|
+
export declare class DefaultLogoutHandler extends LogoutHandler {
|
|
9
|
+
Priority: number;
|
|
10
|
+
protected SessionProvider: SessionProvider;
|
|
11
|
+
protected SessionCookieConfig: Record<string, unknown>;
|
|
12
|
+
handle(context: ILogoutContext): Promise<ILogoutResult | null>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=DefaultLogoutHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultLogoutHandler.d.ts","sourceRoot":"","sources":["../../../src/handlers/DefaultLogoutHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5E;;;;GAIG;AACH,qBACa,oBAAqB,SAAQ,aAAa;IAC9C,QAAQ,SAAO;IAGtB,SAAS,CAAC,eAAe,EAAG,eAAe,CAAC;IAG5C,SAAS,CAAC,mBAAmB,EAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3C,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;CAuB5E"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultLogoutHandler = void 0;
|
|
13
|
+
const di_1 = require("@spinajs/di");
|
|
14
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
15
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
16
|
+
const logout_js_1 = require("../logout.js");
|
|
17
|
+
/**
|
|
18
|
+
* Default logout handler: deletes the session and clears the ssid cookie.
|
|
19
|
+
* Runs last (priority 999) so any earlier handler can short-circuit (e.g.
|
|
20
|
+
* the impersonation revert handler) before the session is destroyed.
|
|
21
|
+
*/
|
|
22
|
+
let DefaultLogoutHandler = class DefaultLogoutHandler extends logout_js_1.LogoutHandler {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.Priority = 999;
|
|
26
|
+
}
|
|
27
|
+
async handle(context) {
|
|
28
|
+
if (!context.Ssid) {
|
|
29
|
+
// Nothing to delete; still return a result so the chain stops.
|
|
30
|
+
return { Body: null };
|
|
31
|
+
}
|
|
32
|
+
await this.SessionProvider.delete(context.Ssid);
|
|
33
|
+
return {
|
|
34
|
+
Body: null,
|
|
35
|
+
Cookies: [
|
|
36
|
+
{
|
|
37
|
+
Name: 'ssid',
|
|
38
|
+
Value: '',
|
|
39
|
+
Options: {
|
|
40
|
+
httpOnly: true,
|
|
41
|
+
maxAge: 0,
|
|
42
|
+
...this.SessionCookieConfig,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.DefaultLogoutHandler = DefaultLogoutHandler;
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, configuration_1.AutoinjectService)('rbac.session'),
|
|
52
|
+
__metadata("design:type", rbac_1.SessionProvider)
|
|
53
|
+
], DefaultLogoutHandler.prototype, "SessionProvider", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
(0, configuration_1.Config)('rbac.session.cookie', {}),
|
|
56
|
+
__metadata("design:type", Object)
|
|
57
|
+
], DefaultLogoutHandler.prototype, "SessionCookieConfig", void 0);
|
|
58
|
+
exports.DefaultLogoutHandler = DefaultLogoutHandler = __decorate([
|
|
59
|
+
(0, di_1.Injectable)(logout_js_1.LogoutHandler)
|
|
60
|
+
], DefaultLogoutHandler);
|
|
61
|
+
//# sourceMappingURL=DefaultLogoutHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DefaultLogoutHandler.js","sourceRoot":"","sources":["../../../src/handlers/DefaultLogoutHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAyC;AACzC,0DAAmE;AACnE,wCAAgD;AAChD,4CAA4E;AAE5E;;;;GAIG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,yBAAa;IAAhD;;QACE,aAAQ,GAAG,GAAG,CAAC;IA+BxB,CAAC;IAvBQ,KAAK,CAAC,MAAM,CAAC,OAAuB;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAClB,+DAA+D;YAC/D,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACxB,CAAC;QAED,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAEhD,OAAO;YACL,IAAI,EAAE,IAAI;YACV,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,KAAK,EAAE,EAAE;oBACT,OAAO,EAAE;wBACP,QAAQ,EAAE,IAAI;wBACd,MAAM,EAAE,CAAC;wBACT,GAAG,IAAI,CAAC,mBAAmB;qBAC5B;iBACF;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAhCY,oDAAoB;AAIrB;IADT,IAAA,iCAAiB,EAAC,cAAc,CAAC;8BACN,sBAAe;6DAAC;AAGlC;IADT,IAAA,sBAAM,EAAC,qBAAqB,EAAE,EAAE,CAAC;;iEACsB;+BAP7C,oBAAoB;IADhC,IAAA,eAAU,EAAC,yBAAa,CAAC;GACb,oBAAoB,CAgChC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SessionProvider, User } from '@spinajs/rbac';
|
|
2
|
+
import { LogoutHandler, ILogoutContext, ILogoutResult } from '../logout.js';
|
|
3
|
+
/**
|
|
4
|
+
* Logout handler that detects an active impersonation and reverts it instead
|
|
5
|
+
* of destroying the session. Runs early (priority 10) so it short-circuits
|
|
6
|
+
* the default session-deletion handler when applicable.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ImpersonationLogoutHandler extends LogoutHandler {
|
|
9
|
+
Priority: number;
|
|
10
|
+
protected SessionProvider: SessionProvider;
|
|
11
|
+
handle(context: ILogoutContext): Promise<ILogoutResult | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Hook for tests to intercept event emission without stubbing the module-level
|
|
14
|
+
* `_ev` ESM binding.
|
|
15
|
+
*/
|
|
16
|
+
protected emitEvent(original: User, target: User): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ImpersonationLogoutHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImpersonationLogoutHandler.d.ts","sourceRoot":"","sources":["../../../src/handlers/ImpersonationLogoutHandler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,IAAI,EAA0B,MAAM,eAAe,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE5E;;;;GAIG;AACH,qBACa,0BAA2B,SAAQ,aAAa;IACpD,QAAQ,SAAM;IAGrB,SAAS,CAAC,eAAe,EAAG,eAAe,CAAC;IAE/B,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IA0B3E;;;OAGG;IACH,SAAS,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAGjE"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ImpersonationLogoutHandler = void 0;
|
|
13
|
+
const di_1 = require("@spinajs/di");
|
|
14
|
+
const configuration_1 = require("@spinajs/configuration");
|
|
15
|
+
const rbac_1 = require("@spinajs/rbac");
|
|
16
|
+
const queue_1 = require("@spinajs/queue");
|
|
17
|
+
const logout_js_1 = require("../logout.js");
|
|
18
|
+
/**
|
|
19
|
+
* Logout handler that detects an active impersonation and reverts it instead
|
|
20
|
+
* of destroying the session. Runs early (priority 10) so it short-circuits
|
|
21
|
+
* the default session-deletion handler when applicable.
|
|
22
|
+
*/
|
|
23
|
+
let ImpersonationLogoutHandler = class ImpersonationLogoutHandler extends logout_js_1.LogoutHandler {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.Priority = 10;
|
|
27
|
+
}
|
|
28
|
+
async handle(context) {
|
|
29
|
+
const session = context.Session;
|
|
30
|
+
if (!session)
|
|
31
|
+
return null;
|
|
32
|
+
const impersonatorUuid = session.Data.get('Impersonator');
|
|
33
|
+
if (!impersonatorUuid)
|
|
34
|
+
return null;
|
|
35
|
+
const original = await rbac_1.User.getByUuid(impersonatorUuid);
|
|
36
|
+
session.Data.set('User', original.Uuid);
|
|
37
|
+
session.Data.delete('Impersonator');
|
|
38
|
+
session.Data.delete('ImpersonationStartedAt');
|
|
39
|
+
const restoredActiveRole = session.Data.get('OriginalActiveRole') ?? original.Role?.[0];
|
|
40
|
+
if (restoredActiveRole) {
|
|
41
|
+
session.Data.set('ActiveRole', restoredActiveRole);
|
|
42
|
+
}
|
|
43
|
+
session.Data.delete('OriginalActiveRole');
|
|
44
|
+
await this.SessionProvider.save(session);
|
|
45
|
+
await this.emitEvent(original, context.User);
|
|
46
|
+
// Take ownership of the response: no cookie change — the original user's
|
|
47
|
+
// session continues.
|
|
48
|
+
return { Body: { ImpersonationEnded: true } };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hook for tests to intercept event emission without stubbing the module-level
|
|
52
|
+
* `_ev` ESM binding.
|
|
53
|
+
*/
|
|
54
|
+
emitEvent(original, target) {
|
|
55
|
+
return (0, queue_1._ev)(new rbac_1.UserImpersonationEnded(original, target))();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
exports.ImpersonationLogoutHandler = ImpersonationLogoutHandler;
|
|
59
|
+
__decorate([
|
|
60
|
+
(0, configuration_1.AutoinjectService)('rbac.session'),
|
|
61
|
+
__metadata("design:type", rbac_1.SessionProvider)
|
|
62
|
+
], ImpersonationLogoutHandler.prototype, "SessionProvider", void 0);
|
|
63
|
+
exports.ImpersonationLogoutHandler = ImpersonationLogoutHandler = __decorate([
|
|
64
|
+
(0, di_1.Injectable)(logout_js_1.LogoutHandler)
|
|
65
|
+
], ImpersonationLogoutHandler);
|
|
66
|
+
//# sourceMappingURL=ImpersonationLogoutHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ImpersonationLogoutHandler.js","sourceRoot":"","sources":["../../../src/handlers/ImpersonationLogoutHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAyC;AACzC,0DAA2D;AAC3D,wCAA8E;AAC9E,0CAAqC;AACrC,4CAA4E;AAE5E;;;;GAIG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA2B,SAAQ,yBAAa;IAAtD;;QACE,aAAQ,GAAG,EAAE,CAAC;IAsCvB,CAAC;IAjCQ,KAAK,CAAC,MAAM,CAAC,OAAuB;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAChC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAE1B,MAAM,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAuB,CAAC;QAChF,IAAI,CAAC,gBAAgB;YAAE,OAAO,IAA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 -1,6 +1,11 @@
|
|
|
1
1
|
import { Bootstrapper } from '@spinajs/di';
|
|
2
2
|
export * from './controllers/LoginController.js';
|
|
3
|
+
export * from './controllers/ActiveRoleController.js';
|
|
4
|
+
export * from './controllers/ImpersonationController.js';
|
|
3
5
|
export * from './controllers/UserController.js';
|
|
6
|
+
export * from './logout.js';
|
|
7
|
+
export * from './handlers/ImpersonationLogoutHandler.js';
|
|
8
|
+
export * from './handlers/DefaultLogoutHandler.js';
|
|
4
9
|
export * from './controllers/UserMetadataController.js';
|
|
5
10
|
export * from "./controllers/TwoFactorAuthController.js";
|
|
6
11
|
export * from "./cli/EnableUser2Fa.js";
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAIvD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAIvD,cAAc,kCAAkC,CAAC;AACjD,cAAc,uCAAuC,CAAC;AACtD,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAEhD,cAAc,aAAa,CAAC;AAC5B,cAAc,0CAA0C,CAAC;AACzD,cAAc,oCAAoC,CAAC;AACnD,cAAc,yCAAyC,CAAC;AACxD,cAAc,0CAA0C,CAAC;AAEzD,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,kBAAkB,CAAC;AAGjC,qBACa,wBAAyB,SAAQ,YAAY;IAC/C,SAAS,IAAI,IAAI;CAO3B"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -25,7 +25,12 @@ const di_1 = require("@spinajs/di");
|
|
|
25
25
|
const rbac_1 = require("@spinajs/rbac");
|
|
26
26
|
const Default2FaToken_js_1 = require("./2fa/Default2FaToken.js");
|
|
27
27
|
__exportStar(require("./controllers/LoginController.js"), exports);
|
|
28
|
+
__exportStar(require("./controllers/ActiveRoleController.js"), exports);
|
|
29
|
+
__exportStar(require("./controllers/ImpersonationController.js"), exports);
|
|
28
30
|
__exportStar(require("./controllers/UserController.js"), exports);
|
|
31
|
+
__exportStar(require("./logout.js"), exports);
|
|
32
|
+
__exportStar(require("./handlers/ImpersonationLogoutHandler.js"), exports);
|
|
33
|
+
__exportStar(require("./handlers/DefaultLogoutHandler.js"), exports);
|
|
29
34
|
__exportStar(require("./controllers/UserMetadataController.js"), exports);
|
|
30
35
|
__exportStar(require("./controllers/TwoFactorAuthController.js"), exports);
|
|
31
36
|
__exportStar(require("./cli/EnableUser2Fa.js"), exports);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAuD;AACvD,wCAAiD;AACjD,iEAAkE;AAElE,mEAAiD;AACjD,kEAAgD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAuD;AACvD,wCAAiD;AACjD,iEAAkE;AAElE,mEAAiD;AACjD,wEAAsD;AACtD,2EAAyD;AACzD,kEAAgD;AAEhD,8CAA4B;AAC5B,2EAAyD;AACzD,qEAAmD;AACnD,0EAAwD;AACxD,2EAAyD;AAEzD,yDAAuC;AACvC,2DAAyC;AAEzC,mDAAiC;AAI1B,IAAM,wBAAwB,GAA9B,MAAM,wBAAyB,SAAQ,iBAAY;IAC/C,SAAS;QACZ,uBAAgB,CAAC,WAAW,GAAG;YAC3B,GAAG,uBAAgB,CAAC,WAAW;YAC/B,2CAAsB,CAAC,KAAK;YAC5B,2CAAsB,CAAC,GAAG;SAC7B,CAAA;IACL,CAAC;CACJ,CAAA;AARY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,wBAAwB,CAQpC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ISession, User } from '@spinajs/rbac';
|
|
2
|
+
/**
|
|
3
|
+
* Per-request context handed to each {@link LogoutHandler} during logout.
|
|
4
|
+
* The session may be null when the caller has no active session — handlers
|
|
5
|
+
* should treat that as a no-op.
|
|
6
|
+
*/
|
|
7
|
+
export interface ILogoutContext {
|
|
8
|
+
/** Raw signed session cookie value (already unsigned by the framework) */
|
|
9
|
+
Ssid: string;
|
|
10
|
+
/** Restored session, or null when none is active */
|
|
11
|
+
Session: ISession | null;
|
|
12
|
+
/** Logged-in user as resolved by RbacMiddleware */
|
|
13
|
+
User: User;
|
|
14
|
+
}
|
|
15
|
+
/** Cookie operation a handler may attach to its response */
|
|
16
|
+
export interface ILogoutCookie {
|
|
17
|
+
Name: string;
|
|
18
|
+
Value: string;
|
|
19
|
+
Options: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** Response payload a handler returns when it takes ownership of the logout */
|
|
22
|
+
export interface ILogoutResult {
|
|
23
|
+
/** Response body */
|
|
24
|
+
Body?: unknown;
|
|
25
|
+
/** Cookie operations to attach */
|
|
26
|
+
Cookies?: ILogoutCookie[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Pluggable logout step. Handlers are resolved via `DI.resolve(Array.ofType(LogoutHandler))`
|
|
30
|
+
* by the logout controller and executed in ascending Priority order. The first
|
|
31
|
+
* handler that returns a non-null result takes ownership of the response — the
|
|
32
|
+
* chain stops there. Returning null defers to the next handler.
|
|
33
|
+
*
|
|
34
|
+
* Built-ins:
|
|
35
|
+
* - {@link ImpersonationLogoutHandler} (priority 10) — when an impersonation
|
|
36
|
+
* is active, revert it and keep the session alive.
|
|
37
|
+
* - {@link DefaultLogoutHandler} (priority 999) — destroy the session and
|
|
38
|
+
* clear the ssid cookie.
|
|
39
|
+
*
|
|
40
|
+
* Register custom handlers with @Injectable(LogoutHandler). Choose a Priority
|
|
41
|
+
* lower than 999 to run before the default session destruction.
|
|
42
|
+
*/
|
|
43
|
+
export declare abstract class LogoutHandler {
|
|
44
|
+
/**
|
|
45
|
+
* Lower runs first. Default 100. The default cleanup handler runs at 999;
|
|
46
|
+
* pick a value below that to run before it.
|
|
47
|
+
*/
|
|
48
|
+
Priority: number;
|
|
49
|
+
abstract handle(context: ILogoutContext): Promise<ILogoutResult | null>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=logout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../src/logout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IAEb,oDAAoD;IACpD,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEzB,mDAAmD;IACnD,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,4DAA4D;AAC5D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,+EAA+E;AAC/E,MAAM,WAAW,aAAa;IAC5B,oBAAoB;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,kCAAkC;IAClC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,8BAAsB,aAAa;IACjC;;;OAGG;IACI,QAAQ,EAAE,MAAM,CAAO;aAEd,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;CAC/E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogoutHandler = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Pluggable logout step. Handlers are resolved via `DI.resolve(Array.ofType(LogoutHandler))`
|
|
6
|
+
* by the logout controller and executed in ascending Priority order. The first
|
|
7
|
+
* handler that returns a non-null result takes ownership of the response — the
|
|
8
|
+
* chain stops there. Returning null defers to the next handler.
|
|
9
|
+
*
|
|
10
|
+
* Built-ins:
|
|
11
|
+
* - {@link ImpersonationLogoutHandler} (priority 10) — when an impersonation
|
|
12
|
+
* is active, revert it and keep the session alive.
|
|
13
|
+
* - {@link DefaultLogoutHandler} (priority 999) — destroy the session and
|
|
14
|
+
* clear the ssid cookie.
|
|
15
|
+
*
|
|
16
|
+
* Register custom handlers with @Injectable(LogoutHandler). Choose a Priority
|
|
17
|
+
* lower than 999 to run before the default session destruction.
|
|
18
|
+
*/
|
|
19
|
+
class LogoutHandler {
|
|
20
|
+
constructor() {
|
|
21
|
+
/**
|
|
22
|
+
* Lower runs first. Default 100. The default cleanup handler runs at 999;
|
|
23
|
+
* pick a value below that to run before it.
|
|
24
|
+
*/
|
|
25
|
+
this.Priority = 100;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.LogoutHandler = LogoutHandler;
|
|
29
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/logout.ts"],"names":[],"mappings":";;;AAkCA;;;;;;;;;;;;;;GAcG;AACH,MAAsB,aAAa;IAAnC;QACE;;;WAGG;QACI,aAAQ,GAAW,GAAG,CAAC;IAGhC,CAAC;CAAA;AARD,sCAQC"}
|