@nest-boot/auth 8.0.5-beta.3 → 8.0.5-beta.4
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/README.md +13 -7
- package/dist/abilities/auth.ability.d.ts +6 -0
- package/dist/abilities/{user.ability.js → auth.ability.js} +4 -4
- package/dist/abilities/auth.ability.js.map +1 -0
- package/dist/abilities/index.d.ts +1 -2
- package/dist/abilities/index.js +1 -2
- package/dist/abilities/index.js.map +1 -1
- package/dist/auth-module-options.interface.d.ts +3 -0
- package/dist/auth.guard.d.ts +3 -9
- package/dist/auth.guard.js +13 -38
- package/dist/auth.guard.js.map +1 -1
- package/dist/auth.module.js +0 -3
- package/dist/auth.module.js.map +1 -1
- package/dist/decorators/can.decorator.d.ts +3 -11
- package/dist/decorators/can.decorator.js +8 -14
- package/dist/decorators/can.decorator.js.map +1 -1
- package/dist/decorators/index.d.ts +0 -2
- package/dist/decorators/index.js +0 -2
- package/dist/decorators/index.js.map +1 -1
- package/dist/entities/account.entity.d.ts +1 -1
- package/dist/entities/account.entity.js +1 -1
- package/dist/entities/invitation.entity.d.ts +2 -0
- package/dist/entities/invitation.entity.js +9 -0
- package/dist/entities/invitation.entity.js.map +1 -1
- package/dist/entities/member.entity.d.ts +2 -0
- package/dist/entities/member.entity.js +9 -0
- package/dist/entities/member.entity.js.map +1 -1
- package/dist/entities/workspace-api-key.entity.d.ts +2 -0
- package/dist/entities/workspace-api-key.entity.js +9 -0
- package/dist/entities/workspace-api-key.entity.js.map +1 -1
- package/dist/index.d.ts +4 -8
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/api-key-lifecycle.d.ts +14 -0
- package/dist/infrastructure/api-key-lifecycle.js +19 -0
- package/dist/infrastructure/api-key-lifecycle.js.map +1 -1
- package/dist/infrastructure/auth-ability.factory.d.ts +4 -9
- package/dist/infrastructure/auth-ability.factory.js +23 -21
- package/dist/infrastructure/auth-ability.factory.js.map +1 -1
- package/dist/infrastructure/auth-service.providers.js +9 -11
- package/dist/infrastructure/auth-service.providers.js.map +1 -1
- package/dist/infrastructure/request-identity.d.ts +16 -4
- package/dist/infrastructure/request-identity.js +61 -40
- package/dist/infrastructure/request-identity.js.map +1 -1
- package/dist/interfaces/ability-context.interface.d.ts +16 -0
- package/dist/interfaces/ability-context.interface.js +2 -0
- package/dist/interfaces/ability-context.interface.js.map +1 -0
- package/dist/interfaces/ability-rules.interface.d.ts +8 -2
- package/dist/interfaces/auth-module-user-options.interface.d.ts +0 -3
- package/dist/interfaces/auth-module-workspace-options.interface.d.ts +0 -3
- package/dist/interfaces/{user-can-metadata.interface.d.ts → can-metadata.interface.d.ts} +2 -2
- package/dist/interfaces/can-metadata.interface.js +2 -0
- package/dist/interfaces/can-metadata.interface.js.map +1 -0
- package/dist/permission.constants.d.ts +2 -4
- package/dist/permission.constants.js +2 -4
- package/dist/permission.constants.js.map +1 -1
- package/dist/resolvers/auth.resolver.d.ts +2 -4
- package/dist/resolvers/auth.resolver.js +5 -16
- package/dist/resolvers/auth.resolver.js.map +1 -1
- package/dist/services/account.service.d.ts +1 -3
- package/dist/services/account.service.js +4 -7
- package/dist/services/account.service.js.map +1 -1
- package/dist/services/invitation.service.d.ts +1 -3
- package/dist/services/invitation.service.js +32 -32
- package/dist/services/invitation.service.js.map +1 -1
- package/dist/services/member.service.d.ts +1 -3
- package/dist/services/member.service.js +50 -51
- package/dist/services/member.service.js.map +1 -1
- package/dist/services/session.service.d.ts +1 -4
- package/dist/services/session.service.js +11 -15
- package/dist/services/session.service.js.map +1 -1
- package/dist/services/user-api-key.service.d.ts +3 -7
- package/dist/services/user-api-key.service.js +52 -73
- package/dist/services/user-api-key.service.js.map +1 -1
- package/dist/services/user-deletion.service.js.map +1 -1
- package/dist/services/user.service.d.ts +1 -3
- package/dist/services/user.service.js +38 -42
- package/dist/services/user.service.js.map +1 -1
- package/dist/services/workspace-api-key.service.d.ts +3 -7
- package/dist/services/workspace-api-key.service.js +50 -71
- package/dist/services/workspace-api-key.service.js.map +1 -1
- package/dist/services/workspace.service.d.ts +1 -3
- package/dist/services/workspace.service.js +22 -24
- package/dist/services/workspace.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/build-ability-callback.type.d.ts +4 -0
- package/dist/types/build-ability-callback.type.js +2 -0
- package/dist/types/build-ability-callback.type.js.map +1 -0
- package/dist/utils/api-key-permissions.util.d.ts +2 -0
- package/dist/utils/api-key-permissions.util.js +9 -0
- package/dist/utils/api-key-permissions.util.js.map +1 -1
- package/dist/utils/assert-can.util.d.ts +3 -0
- package/dist/utils/assert-can.util.js +8 -0
- package/dist/utils/assert-can.util.js.map +1 -0
- package/dist/utils/build-request-ability.util.d.ts +3 -6
- package/dist/utils/build-request-ability.util.js +25 -15
- package/dist/utils/build-request-ability.util.js.map +1 -1
- package/dist/utils/can.util.d.ts +2 -3
- package/dist/utils/can.util.js +9 -7
- package/dist/utils/can.util.js.map +1 -1
- package/dist/utils/extend-ability.util.d.ts +5 -1
- package/dist/utils/extend-ability.util.js +13 -6
- package/dist/utils/extend-ability.util.js.map +1 -1
- package/dist/utils/get-ability.util.d.ts +5 -0
- package/dist/utils/get-ability.util.js +20 -0
- package/dist/utils/get-ability.util.js.map +1 -0
- package/dist/utils/permission-grants.util.d.ts +9 -0
- package/dist/utils/permission-grants.util.js +25 -0
- package/dist/utils/permission-grants.util.js.map +1 -0
- package/package.json +9 -9
- package/dist/abilities/user.ability.d.ts +0 -8
- package/dist/abilities/user.ability.js.map +0 -1
- package/dist/abilities/workspace.ability.d.ts +0 -8
- package/dist/abilities/workspace.ability.js +0 -13
- package/dist/abilities/workspace.ability.js.map +0 -1
- package/dist/decorators/user-can.decorator.d.ts +0 -13
- package/dist/decorators/user-can.decorator.js +0 -21
- package/dist/decorators/user-can.decorator.js.map +0 -1
- package/dist/decorators/workspace-can.decorator.d.ts +0 -13
- package/dist/decorators/workspace-can.decorator.js +0 -21
- package/dist/decorators/workspace-can.decorator.js.map +0 -1
- package/dist/interfaces/can-options.interface.d.ts +0 -5
- package/dist/interfaces/can-options.interface.js +0 -2
- package/dist/interfaces/can-options.interface.js.map +0 -1
- package/dist/interfaces/user-can-metadata.interface.js +0 -2
- package/dist/interfaces/user-can-metadata.interface.js.map +0 -1
- package/dist/interfaces/workspace-can-metadata.interface.d.ts +0 -9
- package/dist/interfaces/workspace-can-metadata.interface.js +0 -2
- package/dist/interfaces/workspace-can-metadata.interface.js.map +0 -1
- package/dist/services/access-control.service.d.ts +0 -54
- package/dist/services/access-control.service.js +0 -208
- package/dist/services/access-control.service.js.map +0 -1
- package/dist/types/build-user-ability-callback.type.d.ts +0 -10
- package/dist/types/build-user-ability-callback.type.js +0 -2
- package/dist/types/build-user-ability-callback.type.js.map +0 -1
- package/dist/types/build-workspace-ability-callback.type.d.ts +0 -10
- package/dist/types/build-workspace-ability-callback.type.js +0 -2
- package/dist/types/build-workspace-ability-callback.type.js.map +0 -1
- package/dist/utils/get-user-ability.util.d.ts +0 -3
- package/dist/utils/get-user-ability.util.js +0 -14
- package/dist/utils/get-user-ability.util.js.map +0 -1
- package/dist/utils/get-workspace-ability.util.d.ts +0 -3
- package/dist/utils/get-workspace-ability.util.js +0 -14
- package/dist/utils/get-workspace-ability.util.js.map +0 -1
- package/dist/utils/user-can.util.d.ts +0 -3
- package/dist/utils/user-can.util.js +0 -9
- package/dist/utils/user-can.util.js.map +0 -1
- package/dist/utils/workspace-can.util.d.ts +0 -3
- package/dist/utils/workspace-can.util.js +0 -10
- package/dist/utils/workspace-can.util.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export * from "./inputs/update-user-api-key.input.js";
|
|
|
38
38
|
export * from "./inputs/update-workspace.input.js";
|
|
39
39
|
export * from "./inputs/update-workspace-api-key.input.js";
|
|
40
40
|
export * from "./inputs/user-id.input.js";
|
|
41
|
+
export * from "./interfaces/ability-context.interface.js";
|
|
41
42
|
export * from "./interfaces/ability-rules.interface.js";
|
|
42
43
|
export * from "./interfaces/accept-invitation-result.interface.js";
|
|
43
44
|
export * from "./interfaces/add-member-options.interface.js";
|
|
@@ -86,7 +87,6 @@ export * from "./interfaces/auth-social-provider-user-info.interface.js";
|
|
|
86
87
|
export * from "./interfaces/auth-user.interface.js";
|
|
87
88
|
export * from "./interfaces/authenticated-session.interface.js";
|
|
88
89
|
export * from "./interfaces/ban-user-options.interface.js";
|
|
89
|
-
export * from "./interfaces/can-options.interface.js";
|
|
90
90
|
export * from "./interfaces/change-auth-email-options.interface.js";
|
|
91
91
|
export * from "./interfaces/change-auth-password-options.interface.js";
|
|
92
92
|
export * from "./interfaces/change-auth-password-result.interface.js";
|
|
@@ -172,7 +172,6 @@ export * from "./resolvers/user.resolver.js";
|
|
|
172
172
|
export * from "./resolvers/user-api-key.resolver.js";
|
|
173
173
|
export * from "./resolvers/workspace.resolver.js";
|
|
174
174
|
export * from "./resolvers/workspace-api-key.resolver.js";
|
|
175
|
-
export * from "./services/access-control.service.js";
|
|
176
175
|
export * from "./services/account.service.js";
|
|
177
176
|
export * from "./services/auth.service.js";
|
|
178
177
|
export * from "./services/invitation.service.js";
|
|
@@ -194,19 +193,16 @@ export * from "./types/auth-oauth-token-endpoint-auth.type.js";
|
|
|
194
193
|
export * from "./types/auth-send-invitation-email.type.js";
|
|
195
194
|
export * from "./types/auth-send-reset-password.type.js";
|
|
196
195
|
export * from "./types/auth-send-verification-email.type.js";
|
|
197
|
-
export * from "./types/build-
|
|
198
|
-
export * from "./types/build-workspace-ability-callback.type.js";
|
|
196
|
+
export * from "./types/build-ability-callback.type.js";
|
|
199
197
|
export * from "./types/can-subject.type.js";
|
|
200
198
|
export * from "./types/can-subject-factory.type.js";
|
|
201
199
|
export * from "./types/permission-name.type.js";
|
|
202
200
|
export * from "./types/role-name.type.js";
|
|
203
201
|
export * from "./types/route-argument-metadata.type.js";
|
|
204
202
|
export * from "./user.constants.js";
|
|
203
|
+
export { assertCan } from "./utils/assert-can.util.js";
|
|
205
204
|
export * from "./utils/can.util.js";
|
|
206
205
|
export * from "./utils/extract-api-key.util.js";
|
|
207
|
-
export
|
|
208
|
-
export * from "./utils/get-workspace-ability.util.js";
|
|
206
|
+
export { getAbility } from "./utils/get-ability.util.js";
|
|
209
207
|
export * from "./utils/serialize-ability-rules.util.js";
|
|
210
|
-
export * from "./utils/user-can.util.js";
|
|
211
|
-
export * from "./utils/workspace-can.util.js";
|
|
212
208
|
export * from "./workspace.constants.js";
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ export * from "./inputs/update-user-api-key.input.js";
|
|
|
38
38
|
export * from "./inputs/update-workspace.input.js";
|
|
39
39
|
export * from "./inputs/update-workspace-api-key.input.js";
|
|
40
40
|
export * from "./inputs/user-id.input.js";
|
|
41
|
+
export * from "./interfaces/ability-context.interface.js";
|
|
41
42
|
export * from "./interfaces/ability-rules.interface.js";
|
|
42
43
|
export * from "./interfaces/accept-invitation-result.interface.js";
|
|
43
44
|
export * from "./interfaces/add-member-options.interface.js";
|
|
@@ -86,7 +87,6 @@ export * from "./interfaces/auth-social-provider-user-info.interface.js";
|
|
|
86
87
|
export * from "./interfaces/auth-user.interface.js";
|
|
87
88
|
export * from "./interfaces/authenticated-session.interface.js";
|
|
88
89
|
export * from "./interfaces/ban-user-options.interface.js";
|
|
89
|
-
export * from "./interfaces/can-options.interface.js";
|
|
90
90
|
export * from "./interfaces/change-auth-email-options.interface.js";
|
|
91
91
|
export * from "./interfaces/change-auth-password-options.interface.js";
|
|
92
92
|
export * from "./interfaces/change-auth-password-result.interface.js";
|
|
@@ -172,7 +172,6 @@ export * from "./resolvers/user.resolver.js";
|
|
|
172
172
|
export * from "./resolvers/user-api-key.resolver.js";
|
|
173
173
|
export * from "./resolvers/workspace.resolver.js";
|
|
174
174
|
export * from "./resolvers/workspace-api-key.resolver.js";
|
|
175
|
-
export * from "./services/access-control.service.js";
|
|
176
175
|
export * from "./services/account.service.js";
|
|
177
176
|
export * from "./services/auth.service.js";
|
|
178
177
|
export * from "./services/invitation.service.js";
|
|
@@ -193,20 +192,17 @@ export * from "./types/auth-oauth-token-endpoint-auth.type.js";
|
|
|
193
192
|
export * from "./types/auth-send-invitation-email.type.js";
|
|
194
193
|
export * from "./types/auth-send-reset-password.type.js";
|
|
195
194
|
export * from "./types/auth-send-verification-email.type.js";
|
|
196
|
-
export * from "./types/build-
|
|
197
|
-
export * from "./types/build-workspace-ability-callback.type.js";
|
|
195
|
+
export * from "./types/build-ability-callback.type.js";
|
|
198
196
|
export * from "./types/can-subject.type.js";
|
|
199
197
|
export * from "./types/can-subject-factory.type.js";
|
|
200
198
|
export * from "./types/permission-name.type.js";
|
|
201
199
|
export * from "./types/role-name.type.js";
|
|
202
200
|
export * from "./types/route-argument-metadata.type.js";
|
|
203
201
|
export * from "./user.constants.js";
|
|
202
|
+
export { assertCan } from "./utils/assert-can.util.js";
|
|
204
203
|
export * from "./utils/can.util.js";
|
|
205
204
|
export * from "./utils/extract-api-key.util.js";
|
|
206
|
-
export
|
|
207
|
-
export * from "./utils/get-workspace-ability.util.js";
|
|
205
|
+
export { getAbility } from "./utils/get-ability.util.js";
|
|
208
206
|
export * from "./utils/serialize-ability-rules.util.js";
|
|
209
|
-
export * from "./utils/user-can.util.js";
|
|
210
|
-
export * from "./utils/workspace-can.util.js";
|
|
211
207
|
export * from "./workspace.constants.js";
|
|
212
208
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,gCAAgC,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC7D,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,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AAC;AAC/D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,4CAA4C,CAAC;AAC3D,cAAc,0CAA0C,CAAC;AACzD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,wCAAwC,CAAC;AACvD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yCAAyC,CAAC;AACxD,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,cAAc,yCAAyC,CAAC;AACxD,cAAc,0BAA0B,CAAC"}
|
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
import type { EntityManager } from "@mikro-orm/core";
|
|
2
2
|
import type { AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
3
|
+
import type { CreateApiKeyOptions } from "../interfaces/create-api-key-options.interface.js";
|
|
3
4
|
import type { UpdateApiKeyOptions } from "../interfaces/update-api-key-options.interface.js";
|
|
4
5
|
import type { ApiKey } from "../types/api-key.type.js";
|
|
5
6
|
/** Persists already-authorized key changes and publishes their committed identity effects. @internal */
|
|
6
7
|
export declare class ApiKeyLifecycle {
|
|
8
|
+
/** Prepares shared credential fields without choosing an owner or authorizing persistence. */
|
|
9
|
+
static prepareCreation(options: CreateApiKeyOptions, permissions: string[]): {
|
|
10
|
+
apiKey: string;
|
|
11
|
+
data: {
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
expiresAt: Date | null;
|
|
14
|
+
key: string;
|
|
15
|
+
name: string;
|
|
16
|
+
permissions: string[];
|
|
17
|
+
prefix: string;
|
|
18
|
+
start: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
7
21
|
/** Validates expiration for both key creation and updates. */
|
|
8
22
|
static assertExpiration(expiresAt: Date | null | undefined): void;
|
|
9
23
|
/** Restores managed fields on persistence failure; never publishes an uncommitted credential. */
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { BadRequestException } from "@nestjs/common";
|
|
2
|
+
import { generateApiKey, hashApiKey, } from "../utils/api-key-credential.util.js";
|
|
2
3
|
import { RequestIdentity } from "./request-identity.js";
|
|
3
4
|
/** Persists already-authorized key changes and publishes their committed identity effects. @internal */
|
|
4
5
|
export class ApiKeyLifecycle {
|
|
6
|
+
/** Prepares shared credential fields without choosing an owner or authorizing persistence. */
|
|
7
|
+
static prepareCreation(options, permissions) {
|
|
8
|
+
this.assertExpiration(options.expiresAt);
|
|
9
|
+
const prefix = options.prefix ?? process.env.API_KEY_PREFIX ?? "sk";
|
|
10
|
+
const apiKey = generateApiKey(prefix);
|
|
11
|
+
return {
|
|
12
|
+
apiKey,
|
|
13
|
+
data: {
|
|
14
|
+
enabled: true,
|
|
15
|
+
expiresAt: options.expiresAt ?? null,
|
|
16
|
+
key: hashApiKey(apiKey),
|
|
17
|
+
name: options.name,
|
|
18
|
+
permissions,
|
|
19
|
+
prefix,
|
|
20
|
+
start: apiKey.slice(0, 8),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
5
24
|
/** Validates expiration for both key creation and updates. */
|
|
6
25
|
static assertExpiration(expiresAt) {
|
|
7
26
|
if (expiresAt && expiresAt <= new Date()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-lifecycle.js","sourceRoot":"","sources":["../../src/infrastructure/api-key-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"api-key-lifecycle.js","sourceRoot":"","sources":["../../src/infrastructure/api-key-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAMrD,OAAO,EACL,cAAc,EACd,UAAU,GACX,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C,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QACxD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Workspace } from "../entities/workspace.entity.js";
|
|
5
|
-
import type { AuthModuleUserOptions } from "../interfaces/auth-module-user-options.interface.js";
|
|
6
|
-
import type { AuthModuleWorkspaceOptions } from "../interfaces/auth-module-workspace-options.interface.js";
|
|
1
|
+
import { AuthAbility } from "../abilities/auth.ability.js";
|
|
2
|
+
import type { AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
3
|
+
import type { AbilityContext } from "../interfaces/ability-context.interface.js";
|
|
7
4
|
/** Owns built-in permission mappings and validates business extensions. @internal */
|
|
8
5
|
export declare class AuthAbilityFactory {
|
|
9
6
|
/** Builds auth rules and restricted extensions from already credential-limited permissions. */
|
|
10
|
-
static
|
|
11
|
-
/** Builds auth rules and restricted extensions from already credential-limited permissions. */
|
|
12
|
-
static createWorkspaceAbility(permissions: readonly string[], workspace: Workspace, options?: AuthModuleWorkspaceOptions): WorkspaceAbility;
|
|
7
|
+
static createAbility(context: AbilityContext, options?: AuthModuleOptions): AuthAbility;
|
|
13
8
|
/** Keeps class checks, tagged objects, and serialized frontend names equivalent. */
|
|
14
9
|
private static addSubjectAliases;
|
|
15
10
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AbilityBuilder, } from "@casl/ability";
|
|
2
|
-
import {
|
|
3
|
-
import { WorkspaceAbility } from "../abilities/workspace.ability.js";
|
|
2
|
+
import { AuthAbility } from "../abilities/auth.ability.js";
|
|
4
3
|
import { Invitation } from "../entities/invitation.entity.js";
|
|
5
4
|
import { Member } from "../entities/member.entity.js";
|
|
6
5
|
import { Session } from "../entities/session.entity.js";
|
|
@@ -15,9 +14,13 @@ import { DEFAULT_WORKSPACE_PERMISSIONS } from "../workspace.constants.js";
|
|
|
15
14
|
/** Owns built-in permission mappings and validates business extensions. @internal */
|
|
16
15
|
export class AuthAbilityFactory {
|
|
17
16
|
/** Builds auth rules and restricted extensions from already credential-limited permissions. */
|
|
18
|
-
static
|
|
19
|
-
const
|
|
20
|
-
|
|
17
|
+
static createAbility(context, options = {}) {
|
|
18
|
+
const snapshot = Object.freeze({
|
|
19
|
+
...context,
|
|
20
|
+
userPermissions: Object.freeze(context.user ? [...context.userPermissions] : []),
|
|
21
|
+
workspacePermissions: Object.freeze(context.workspace ? [...context.workspacePermissions] : []),
|
|
22
|
+
});
|
|
23
|
+
const builder = new AbilityBuilder(AuthAbility);
|
|
21
24
|
// Self-service operations are authorized explicitly by their Services.
|
|
22
25
|
const subjects = {
|
|
23
26
|
user: User,
|
|
@@ -26,40 +29,39 @@ export class AuthAbilityFactory {
|
|
|
26
29
|
workspace: Workspace,
|
|
27
30
|
};
|
|
28
31
|
for (const permission of DEFAULT_USER_PERMISSIONS) {
|
|
29
|
-
if (!
|
|
32
|
+
if (!snapshot.userPermissions.includes(permission))
|
|
30
33
|
continue;
|
|
31
34
|
const [resource, action] = permission.split(":");
|
|
32
35
|
builder.can(action, subjects[resource]);
|
|
33
36
|
}
|
|
34
|
-
const
|
|
35
|
-
if (configure)
|
|
36
|
-
extendAbility(builder, grants, resolveAuthCatalog({ user: options }, "user").permissions, (rules) => configure(rules, grants, user));
|
|
37
|
-
this.addSubjectAliases(builder.rules);
|
|
38
|
-
return builder.build();
|
|
39
|
-
}
|
|
40
|
-
/** Builds auth rules and restricted extensions from already credential-limited permissions. */
|
|
41
|
-
static createWorkspaceAbility(permissions, workspace, options = {}) {
|
|
42
|
-
const grants = Object.freeze([...permissions]);
|
|
43
|
-
const builder = new AbilityBuilder(WorkspaceAbility);
|
|
44
|
-
const subjects = {
|
|
37
|
+
const workspaceSubjects = {
|
|
45
38
|
workspace: Workspace,
|
|
46
39
|
member: Member,
|
|
47
40
|
"workspace-api-key": WorkspaceApiKey,
|
|
48
41
|
};
|
|
49
42
|
for (const permission of DEFAULT_WORKSPACE_PERMISSIONS) {
|
|
50
|
-
if (!
|
|
43
|
+
if (!snapshot.workspace ||
|
|
44
|
+
!snapshot.workspacePermissions.includes(permission))
|
|
51
45
|
continue;
|
|
52
46
|
// Invitation management is one member permission; keep entity checks for CASL conditions.
|
|
53
47
|
if (permission === "member:invite") {
|
|
54
|
-
builder.can(["read", "write"], Invitation
|
|
48
|
+
builder.can(["read", "write"], Invitation, {
|
|
49
|
+
workspaceId: snapshot.workspace.id,
|
|
50
|
+
});
|
|
55
51
|
continue;
|
|
56
52
|
}
|
|
57
53
|
const [resource, action] = permission.split(":");
|
|
58
|
-
|
|
54
|
+
const conditions = resource === "workspace"
|
|
55
|
+
? { id: snapshot.workspace.id }
|
|
56
|
+
: { workspaceId: snapshot.workspace.id };
|
|
57
|
+
builder.can(action, workspaceSubjects[resource], conditions);
|
|
59
58
|
}
|
|
60
59
|
const configure = options.buildAbility;
|
|
61
60
|
if (configure)
|
|
62
|
-
extendAbility(builder,
|
|
61
|
+
extendAbility(builder, snapshot, {
|
|
62
|
+
user: resolveAuthCatalog(options, "user").permissions,
|
|
63
|
+
workspace: resolveAuthCatalog(options, "workspace").permissions,
|
|
64
|
+
}, (rules) => configure(rules, snapshot));
|
|
63
65
|
this.addSubjectAliases(builder.rules);
|
|
64
66
|
return builder.build();
|
|
65
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-ability.factory.js","sourceRoot":"","sources":["../../src/infrastructure/auth-ability.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAKf,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-ability.factory.js","sourceRoot":"","sources":["../../src/infrastructure/auth-ability.factory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAKf,MAAM,eAAe,CAAC;AAEvB,OAAO,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GAAG,CACR,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;oBACzB,IAAI,OAAO,MAAM,KAAK,UAAU;wBAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;oBAC/D,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBACxC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;gBACxD,CAAC,CAAC,CACH;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -2,7 +2,6 @@ import { EntityManager } from "@mikro-orm/core";
|
|
|
2
2
|
import { HashService } from "@nest-boot/hash";
|
|
3
3
|
import { AUTH_TOKEN } from "../auth.constants.js";
|
|
4
4
|
import { MODULE_OPTIONS_TOKEN } from "../auth.module-definition.js";
|
|
5
|
-
import { AccessControlService } from "../services/access-control.service.js";
|
|
6
5
|
import { InvitationService } from "../services/invitation.service.js";
|
|
7
6
|
import { MemberService } from "../services/member.service.js";
|
|
8
7
|
import { SessionService } from "../services/session.service.js";
|
|
@@ -15,20 +14,20 @@ import { createContextualAuthService } from "./create-contextual-auth-service.js
|
|
|
15
14
|
export const authServiceProviders = [
|
|
16
15
|
{
|
|
17
16
|
provide: WorkspaceService,
|
|
18
|
-
inject: [EntityManager, MODULE_OPTIONS_TOKEN
|
|
19
|
-
useFactory: (em, options
|
|
17
|
+
inject: [EntityManager, MODULE_OPTIONS_TOKEN],
|
|
18
|
+
useFactory: (em, options) => createContextualAuthService(em, (manager) => new WorkspaceService(manager, options), {
|
|
20
19
|
createWorkspace: "authentication",
|
|
21
20
|
}),
|
|
22
21
|
},
|
|
23
22
|
{
|
|
24
23
|
provide: MemberService,
|
|
25
|
-
inject: [EntityManager, MODULE_OPTIONS_TOKEN
|
|
26
|
-
useFactory: (em, options
|
|
24
|
+
inject: [EntityManager, MODULE_OPTIONS_TOKEN],
|
|
25
|
+
useFactory: (em, options) => createContextualAuthService(em, (manager) => new MemberService(manager, options), { getUserForMembership: "authentication" }),
|
|
27
26
|
},
|
|
28
27
|
{
|
|
29
28
|
provide: InvitationService,
|
|
30
|
-
inject: [EntityManager, MODULE_OPTIONS_TOKEN
|
|
31
|
-
useFactory: (em, options
|
|
29
|
+
inject: [EntityManager, MODULE_OPTIONS_TOKEN],
|
|
30
|
+
useFactory: (em, options) => createContextualAuthService(em, (manager) => new InvitationService(manager, options), {
|
|
32
31
|
getUserIdForInvitation: "invitation-identity",
|
|
33
32
|
acceptInvitation: "authentication",
|
|
34
33
|
rejectInvitation: "authentication",
|
|
@@ -40,10 +39,9 @@ export const authServiceProviders = [
|
|
|
40
39
|
EntityManager,
|
|
41
40
|
MODULE_OPTIONS_TOKEN,
|
|
42
41
|
HashService,
|
|
43
|
-
AccessControlService,
|
|
44
42
|
UserDeletionService,
|
|
45
43
|
],
|
|
46
|
-
useFactory: (em, options, hash,
|
|
44
|
+
useFactory: (em, options, hash, deletion) => createContextualAuthService(em, (manager) => new UserService(manager, options, hash, deletion), {
|
|
47
45
|
createUser: "authentication",
|
|
48
46
|
banUser: "authentication",
|
|
49
47
|
setUserPassword: "authentication",
|
|
@@ -60,8 +58,8 @@ export const authServiceProviders = [
|
|
|
60
58
|
},
|
|
61
59
|
{
|
|
62
60
|
provide: SessionService,
|
|
63
|
-
inject: [AUTH_TOKEN, EntityManager
|
|
64
|
-
useFactory: (auth, em
|
|
61
|
+
inject: [AUTH_TOKEN, EntityManager],
|
|
62
|
+
useFactory: (auth, em) => createContextualAuthService(em, (manager) => new SessionService(auth, manager), {
|
|
65
63
|
getCurrentAuthenticatedSession: "authentication",
|
|
66
64
|
listCurrentUserSessions: "authentication",
|
|
67
65
|
revokeSession: "authentication",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-service.providers.js","sourceRoot":"","sources":["../../src/infrastructure/auth-service.providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"auth-service.providers.js","sourceRoot":"","sources":["../../src/infrastructure/auth-service.providers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAElF,oGAAoG;AACpG,MAAM,CAAC,MAAM,oBAAoB,GAAe;IAC9C;QACE,OAAO,EAAE,gBAAgB;QACzB,MAAM,EAAE,CAAC,aAAa,EAAE,oBAAoB,CAAC;QAC7C,UAAU,EAAE,CAAC,EAAiB,EAAE,OAA0B,EAAE,EAAE,CAC5D,2BAA2B,CACzB,EAAE,EACF,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,OAA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EAAE,CAAC,aAAa,CAAC;QACvB,UAAU,EAAE,CAAC,EAAiB,EAAE,EAAE,CAChC,2BAA2B,CACzB,EAAE,EACF,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,2BAA2B,CAAC,OAAO,CAAC,EACrD;YACE,QAAQ,EAAE,gBAAgB;SAC3B,CACF;KACJ;IACD;QACE,OAAO,EAAE,cAAc;QACvB,MAAM,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC;QACnC,UAAU,EAAE,CAAC,IAAa,EAAE,EAAiB,EAAE,EAAE,CAC/C,2BAA2B,CACzB,EAAE,EACF,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,EAC9C;YACE,8BAA8B,EAAE,gBAAgB;YAChD,uBAAuB,EAAE,gBAAgB;YACzC,aAAa,EAAE,gBAAgB;YAC/B,kBAAkB,EAAE,gBAAgB;SACrC,CACF;KACJ;CACF,CAAC"}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import type { EntityManager } from "@mikro-orm/core";
|
|
2
2
|
import type { AuthModuleOptions } from "../auth-module-options.interface.js";
|
|
3
3
|
import { Member } from "../entities/member.entity.js";
|
|
4
|
+
import { Session } from "../entities/session.entity.js";
|
|
4
5
|
import { User } from "../entities/user.entity.js";
|
|
6
|
+
import { Workspace } from "../entities/workspace.entity.js";
|
|
5
7
|
import type { RequestIdentityPatch } from "../interfaces/request-identity-patch.interface.js";
|
|
6
8
|
import type { ApiKey } from "../types/api-key.type.js";
|
|
7
9
|
/** Owns request identity publication, authorization invalidation, and database scope. @internal */
|
|
8
10
|
export declare class RequestIdentity {
|
|
11
|
+
/** Throws unless the supplied user is the authenticated user. */
|
|
12
|
+
static assertCurrentUser(user: User): void;
|
|
13
|
+
/** Authorizes an explicit self-service path without granting a general resource ability. */
|
|
14
|
+
static assertUserSession(user: User): void;
|
|
15
|
+
/** Throws unless the supplied session is the authenticated session. */
|
|
16
|
+
static assertCurrentSession(session: Session): void;
|
|
17
|
+
/** Throws unless the supplied workspace is selected for the current request. */
|
|
18
|
+
static assertCurrentWorkspace(workspace: Workspace): void;
|
|
19
|
+
/** Throws unless the supplied member is the current workspace member. */
|
|
20
|
+
static assertCurrentMember(member: Member | null | undefined): void;
|
|
9
21
|
/** Matches credentials by both table and ID. */
|
|
10
22
|
static isCurrentApiKey(apiKey: ApiKey): boolean;
|
|
11
23
|
/** Rejects publishing an authenticating credential before its outer transaction commits. */
|
|
@@ -16,18 +28,18 @@ export declare class RequestIdentity {
|
|
|
16
28
|
static updateMember(em: EntityManager, options: AuthModuleOptions, member: Member): void;
|
|
17
29
|
/** Publishes committed credential changes or revokes the entire request. */
|
|
18
30
|
static updateApiKey(em: EntityManager, options: AuthModuleOptions, apiKey: ApiKey, deleted?: boolean): void;
|
|
19
|
-
/** Prepares
|
|
31
|
+
/** Prepares the request ability once, failing closed when configuration rejects. */
|
|
20
32
|
static prepare(options: AuthModuleOptions): void;
|
|
21
33
|
/** Stages identity while authentication is being resolved, before a guard can run. */
|
|
22
34
|
static stage(patch: RequestIdentityPatch): void;
|
|
23
|
-
/**
|
|
35
|
+
/** Rebuilds one ability, never retaining old grants on failure. */
|
|
24
36
|
static refresh(options: AuthModuleOptions): void;
|
|
25
37
|
/** Publishes a committed identity change; failures revoke the request instead of retaining stale grants. */
|
|
26
38
|
static update(em: EntityManager, options: AuthModuleOptions, patch: RequestIdentityPatch): void;
|
|
27
39
|
/** Removes all credentials without falling back to another authentication method. */
|
|
28
40
|
static clear(em: EntityManager): void;
|
|
29
|
-
/**
|
|
30
|
-
static clearWorkspace(em: EntityManager): void;
|
|
41
|
+
/** Revokes workspace rules and rebuilds the remaining user ability after a committed change. */
|
|
42
|
+
static clearWorkspace(em: EntityManager, options: AuthModuleOptions): void;
|
|
31
43
|
/** Synchronizes only identity values; database policies never receive application permissions. */
|
|
32
44
|
static syncDatabase(em: EntityManager): void;
|
|
33
45
|
private static databaseScope;
|
|
@@ -1,18 +1,63 @@
|
|
|
1
1
|
import { RequestContext } from "@nest-boot/request-context";
|
|
2
|
-
import { BadRequestException } from "@nestjs/common";
|
|
3
|
-
import {
|
|
4
|
-
import { WorkspaceAbility } from "../abilities/workspace.ability.js";
|
|
2
|
+
import { BadRequestException, ForbiddenException } from "@nestjs/common";
|
|
3
|
+
import { AuthAbility } from "../abilities/auth.ability.js";
|
|
5
4
|
import { API_KEY } from "../auth.constants.js";
|
|
6
5
|
import { Member } from "../entities/member.entity.js";
|
|
7
6
|
import { Session } from "../entities/session.entity.js";
|
|
8
7
|
import { User } from "../entities/user.entity.js";
|
|
9
8
|
import { Workspace } from "../entities/workspace.entity.js";
|
|
10
9
|
import { WorkspaceApiKey } from "../entities/workspace-api-key.entity.js";
|
|
11
|
-
import {
|
|
10
|
+
import { buildRequestAbility } from "../utils/build-request-ability.util.js";
|
|
12
11
|
import { getCurrentApiKey } from "../utils/get-current-api-key.util.js";
|
|
13
12
|
import { invalidateRequestPermissions } from "../utils/resolve-request-permissions.util.js";
|
|
14
13
|
/** Owns request identity publication, authorization invalidation, and database scope. @internal */
|
|
15
14
|
export class RequestIdentity {
|
|
15
|
+
/** Throws unless the supplied user is the authenticated user. */
|
|
16
|
+
static assertCurrentUser(user) {
|
|
17
|
+
const currentUser = RequestContext.isActive()
|
|
18
|
+
? RequestContext.get(User)
|
|
19
|
+
: undefined;
|
|
20
|
+
if (!currentUser || String(currentUser.id) !== String(user.id)) {
|
|
21
|
+
throw new ForbiddenException("The operation belongs to another user");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Authorizes an explicit self-service path without granting a general resource ability. */
|
|
25
|
+
static assertUserSession(user) {
|
|
26
|
+
this.assertCurrentUser(user);
|
|
27
|
+
if (getCurrentApiKey()) {
|
|
28
|
+
throw new ForbiddenException("This self-service operation requires a user session");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Throws unless the supplied session is the authenticated session. */
|
|
32
|
+
static assertCurrentSession(session) {
|
|
33
|
+
const currentSession = RequestContext.isActive()
|
|
34
|
+
? RequestContext.get(Session)
|
|
35
|
+
: undefined;
|
|
36
|
+
if (currentSession?.token !== session.token) {
|
|
37
|
+
throw new ForbiddenException("The operation belongs to another session");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Throws unless the supplied workspace is selected for the current request. */
|
|
41
|
+
static assertCurrentWorkspace(workspace) {
|
|
42
|
+
const currentWorkspace = RequestContext.isActive()
|
|
43
|
+
? RequestContext.get(Workspace)
|
|
44
|
+
: undefined;
|
|
45
|
+
if (!currentWorkspace ||
|
|
46
|
+
String(currentWorkspace.id) !== String(workspace.id)) {
|
|
47
|
+
throw new ForbiddenException("The operation belongs to another workspace");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Throws unless the supplied member is the current workspace member. */
|
|
51
|
+
static assertCurrentMember(member) {
|
|
52
|
+
const currentMember = RequestContext.isActive()
|
|
53
|
+
? RequestContext.get(Member)
|
|
54
|
+
: undefined;
|
|
55
|
+
if (!member ||
|
|
56
|
+
!currentMember ||
|
|
57
|
+
String(currentMember.id) !== String(member.id)) {
|
|
58
|
+
throw new ForbiddenException("The operation belongs to another workspace member");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
16
61
|
/** Matches credentials by both table and ID. */
|
|
17
62
|
static isCurrentApiKey(apiKey) {
|
|
18
63
|
const current = getCurrentApiKey();
|
|
@@ -38,7 +83,7 @@ export class RequestIdentity {
|
|
|
38
83
|
RequestContext.get(Member)?.id !== member.id)
|
|
39
84
|
return;
|
|
40
85
|
if (member.status !== "ACTIVE")
|
|
41
|
-
this.clearWorkspace(em);
|
|
86
|
+
this.clearWorkspace(em, options);
|
|
42
87
|
else
|
|
43
88
|
this.update(em, options, { member });
|
|
44
89
|
}
|
|
@@ -53,22 +98,11 @@ export class RequestIdentity {
|
|
|
53
98
|
else
|
|
54
99
|
this.update(em, options, { apiKey });
|
|
55
100
|
}
|
|
56
|
-
/** Prepares
|
|
101
|
+
/** Prepares the request ability once, failing closed when configuration rejects. */
|
|
57
102
|
static prepare(options) {
|
|
58
|
-
if (!RequestContext.isActive())
|
|
103
|
+
if (!RequestContext.isActive() || RequestContext.get(AuthAbility))
|
|
59
104
|
return;
|
|
60
|
-
|
|
61
|
-
const user = RequestContext.get(UserAbility) ?? buildRequestUserAbility(options);
|
|
62
|
-
const workspace = RequestContext.get(WorkspaceAbility) ??
|
|
63
|
-
buildRequestWorkspaceAbility(options);
|
|
64
|
-
RequestContext.set(UserAbility, user);
|
|
65
|
-
RequestContext.set(WorkspaceAbility, workspace);
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
RequestContext.set(UserAbility, new UserAbility());
|
|
69
|
-
RequestContext.set(WorkspaceAbility, new WorkspaceAbility());
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
105
|
+
this.refresh(options);
|
|
72
106
|
}
|
|
73
107
|
/** Stages identity while authentication is being resolved, before a guard can run. */
|
|
74
108
|
static stage(patch) {
|
|
@@ -85,20 +119,15 @@ export class RequestIdentity {
|
|
|
85
119
|
if ("apiKey" in patch)
|
|
86
120
|
RequestContext.set(API_KEY, patch.apiKey ?? null);
|
|
87
121
|
invalidateRequestPermissions();
|
|
88
|
-
RequestContext.set(
|
|
89
|
-
RequestContext.set(WorkspaceAbility, null);
|
|
122
|
+
RequestContext.set(AuthAbility, null);
|
|
90
123
|
}
|
|
91
|
-
/**
|
|
124
|
+
/** Rebuilds one ability, never retaining old grants on failure. */
|
|
92
125
|
static refresh(options) {
|
|
93
126
|
if (!RequestContext.isActive())
|
|
94
127
|
return;
|
|
95
128
|
invalidateRequestPermissions();
|
|
96
|
-
RequestContext.set(
|
|
97
|
-
RequestContext.set(
|
|
98
|
-
const user = buildRequestUserAbility(options);
|
|
99
|
-
const workspace = buildRequestWorkspaceAbility(options);
|
|
100
|
-
RequestContext.set(UserAbility, user);
|
|
101
|
-
RequestContext.set(WorkspaceAbility, workspace);
|
|
129
|
+
RequestContext.set(AuthAbility, new AuthAbility());
|
|
130
|
+
RequestContext.set(AuthAbility, buildRequestAbility(options));
|
|
102
131
|
}
|
|
103
132
|
/** Publishes a committed identity change; failures revoke the request instead of retaining stale grants. */
|
|
104
133
|
static update(em, options, patch) {
|
|
@@ -127,8 +156,7 @@ export class RequestIdentity {
|
|
|
127
156
|
apiKey: null,
|
|
128
157
|
});
|
|
129
158
|
if (RequestContext.isActive()) {
|
|
130
|
-
RequestContext.set(
|
|
131
|
-
RequestContext.set(WorkspaceAbility, new WorkspaceAbility());
|
|
159
|
+
RequestContext.set(AuthAbility, new AuthAbility());
|
|
132
160
|
}
|
|
133
161
|
if (em.getSessionContext())
|
|
134
162
|
em.setSessionContext({
|
|
@@ -136,20 +164,13 @@ export class RequestIdentity {
|
|
|
136
164
|
variables: { "app.user.id": "", "app.workspace.id": "" },
|
|
137
165
|
});
|
|
138
166
|
}
|
|
139
|
-
/**
|
|
140
|
-
static clearWorkspace(em) {
|
|
167
|
+
/** Revokes workspace rules and rebuilds the remaining user ability after a committed change. */
|
|
168
|
+
static clearWorkspace(em, options) {
|
|
141
169
|
if (getCurrentApiKey() instanceof WorkspaceApiKey) {
|
|
142
170
|
this.clear(em);
|
|
143
171
|
return;
|
|
144
172
|
}
|
|
145
|
-
|
|
146
|
-
RequestContext.set(Member, null);
|
|
147
|
-
RequestContext.set(Workspace, null);
|
|
148
|
-
invalidateRequestPermissions();
|
|
149
|
-
RequestContext.set(WorkspaceAbility, new WorkspaceAbility());
|
|
150
|
-
}
|
|
151
|
-
if (em.getSessionContext())
|
|
152
|
-
em.setSessionContext({ variables: { "app.workspace.id": "" } });
|
|
173
|
+
this.update(em, options, { member: null, workspace: null });
|
|
153
174
|
}
|
|
154
175
|
/** Synchronizes only identity values; database policies never receive application permissions. */
|
|
155
176
|
static syncDatabase(em) {
|