@spinajs/rbac-http-token 2.0.513 → 2.0.515
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 +62 -6
- package/lib/cjs/actions.d.ts +43 -7
- package/lib/cjs/actions.d.ts.map +1 -1
- package/lib/cjs/actions.js +95 -16
- package/lib/cjs/actions.js.map +1 -1
- package/lib/cjs/cli/CreateToken.js +1 -1
- package/lib/cjs/cli/CreateToken.js.map +1 -1
- package/lib/cjs/cli/GrantTokenRole.js +1 -1
- package/lib/cjs/cli/GrantTokenRole.js.map +1 -1
- package/lib/cjs/config/rbac-http-token.d.ts +17 -0
- package/lib/cjs/config/rbac-http-token.d.ts.map +1 -1
- package/lib/cjs/config/rbac-http-token.js +17 -0
- package/lib/cjs/config/rbac-http-token.js.map +1 -1
- package/lib/cjs/controllers/AccessTokenController.d.ts +38 -5
- package/lib/cjs/controllers/AccessTokenController.d.ts.map +1 -1
- package/lib/cjs/controllers/AccessTokenController.js +60 -6
- package/lib/cjs/controllers/AccessTokenController.js.map +1 -1
- package/lib/cjs/dto/create-token-dto.d.ts +7 -0
- package/lib/cjs/dto/create-token-dto.d.ts.map +1 -1
- package/lib/cjs/dto/create-token-dto.js +7 -1
- package/lib/cjs/dto/create-token-dto.js.map +1 -1
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces.d.ts +58 -0
- package/lib/cjs/interfaces.d.ts.map +1 -1
- package/lib/cjs/interfaces.js +41 -1
- package/lib/cjs/interfaces.js.map +1 -1
- package/lib/cjs/middlewares.d.ts +5 -0
- package/lib/cjs/middlewares.d.ts.map +1 -1
- package/lib/cjs/middlewares.js +11 -1
- package/lib/cjs/middlewares.js.map +1 -1
- package/lib/cjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.d.ts +6 -0
- package/lib/cjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.d.ts.map +1 -0
- package/lib/cjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.js +24 -0
- package/lib/cjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.js.map +1 -0
- package/lib/cjs/models/AccessToken.d.ts +6 -0
- package/lib/cjs/models/AccessToken.d.ts.map +1 -1
- package/lib/cjs/models/AccessToken.js.map +1 -1
- package/lib/cjs/role-policy.d.ts +28 -0
- package/lib/cjs/role-policy.d.ts.map +1 -0
- package/lib/cjs/role-policy.js +52 -0
- package/lib/cjs/role-policy.js.map +1 -0
- package/lib/mjs/actions.d.ts +43 -7
- package/lib/mjs/actions.d.ts.map +1 -1
- package/lib/mjs/actions.js +94 -17
- package/lib/mjs/actions.js.map +1 -1
- package/lib/mjs/cli/CreateToken.js +1 -1
- package/lib/mjs/cli/CreateToken.js.map +1 -1
- package/lib/mjs/cli/GrantTokenRole.js +1 -1
- package/lib/mjs/cli/GrantTokenRole.js.map +1 -1
- package/lib/mjs/config/rbac-http-token.d.ts +17 -0
- package/lib/mjs/config/rbac-http-token.d.ts.map +1 -1
- package/lib/mjs/config/rbac-http-token.js +17 -0
- package/lib/mjs/config/rbac-http-token.js.map +1 -1
- package/lib/mjs/controllers/AccessTokenController.d.ts +38 -5
- package/lib/mjs/controllers/AccessTokenController.d.ts.map +1 -1
- package/lib/mjs/controllers/AccessTokenController.js +62 -8
- package/lib/mjs/controllers/AccessTokenController.js.map +1 -1
- package/lib/mjs/dto/create-token-dto.d.ts +7 -0
- package/lib/mjs/dto/create-token-dto.d.ts.map +1 -1
- package/lib/mjs/dto/create-token-dto.js +7 -1
- package/lib/mjs/dto/create-token-dto.js.map +1 -1
- package/lib/mjs/index.d.ts +3 -0
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +3 -0
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/interfaces.d.ts +58 -0
- package/lib/mjs/interfaces.d.ts.map +1 -1
- package/lib/mjs/interfaces.js +39 -0
- package/lib/mjs/interfaces.js.map +1 -1
- package/lib/mjs/middlewares.d.ts +5 -0
- package/lib/mjs/middlewares.d.ts.map +1 -1
- package/lib/mjs/middlewares.js +11 -1
- package/lib/mjs/middlewares.js.map +1 -1
- package/lib/mjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.d.ts +6 -0
- package/lib/mjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.d.ts.map +1 -0
- package/lib/mjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.js +21 -0
- package/lib/mjs/migrations/RbacHttpTokenProfile_2026_08_21_00_00_00.js.map +1 -0
- package/lib/mjs/models/AccessToken.d.ts +6 -0
- package/lib/mjs/models/AccessToken.d.ts.map +1 -1
- package/lib/mjs/models/AccessToken.js.map +1 -1
- package/lib/mjs/role-policy.d.ts +28 -0
- package/lib/mjs/role-policy.d.ts.map +1 -0
- package/lib/mjs/role-policy.js +48 -0
- package/lib/mjs/role-policy.js.map +1 -0
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +15 -15
package/lib/mjs/actions.d.ts
CHANGED
|
@@ -27,19 +27,53 @@ export declare function _token(token: AccessToken | string): () => Promise<Acces
|
|
|
27
27
|
* populated ( needed for IsBanned checks downstream ).
|
|
28
28
|
*/
|
|
29
29
|
export declare function _owner(user: User | number | string): () => Promise<User>;
|
|
30
|
+
/**
|
|
31
|
+
* Roles the configured {@link AccessTokenRolePolicy} lets `owner` put on a
|
|
32
|
+
* token. Resolved per call rather than cached, so a policy that answers from
|
|
33
|
+
* live state ( the owner's current roles, the application's grants ) is not
|
|
34
|
+
* frozen at boot.
|
|
35
|
+
*
|
|
36
|
+
* Filters the policy's answer down to role names `accesscontrol` actually
|
|
37
|
+
* knows about ( i.e. present in `ac.getGrants()` ). A policy is arbitrary
|
|
38
|
+
* application code and may return a typo'd or stale role name; without this
|
|
39
|
+
* filter such a name would be offered by `GET user/tokens/roles`, accepted by
|
|
40
|
+
* `createToken`/`grantTokenRole` onto a token, and then make every request
|
|
41
|
+
* that token authenticates 500 - `checkRoutePermission` calls
|
|
42
|
+
* `ac.can(roles)[permission](resource)`, and `accesscontrol` throws
|
|
43
|
+
* `AccessControlError` for a role absent from its grants map. A role that
|
|
44
|
+
* grants nothing must never be offered or authorised in the first place.
|
|
45
|
+
*
|
|
46
|
+
* Filters with `Object.hasOwn`, not `Boolean(grants[r])`: `getGrants()` returns a plain
|
|
47
|
+
* object, so `grants['constructor']`, `['toString']`, `['valueOf']`, `['hasOwnProperty']`
|
|
48
|
+
* and `['__proto__']` all resolve truthy through the prototype chain even though no role by
|
|
49
|
+
* that name was ever registered. A policy returning `'constructor'` would otherwise survive
|
|
50
|
+
* this filter, get offered by `GET user/tokens/roles`, and be mintable onto a token.
|
|
51
|
+
*/
|
|
52
|
+
export declare function _allowed_roles(owner: User, profile?: string): Promise<string[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Profiles the configured {@link AccessTokenRolePolicy} lets `owner` pin a
|
|
55
|
+
* token to. Same live-resolution rationale as `_allowed_roles`.
|
|
56
|
+
*/
|
|
57
|
+
export declare function _allowed_profiles(owner: User): Promise<string[]>;
|
|
30
58
|
/**
|
|
31
59
|
* Creates a new access token for a user.
|
|
32
60
|
*
|
|
33
|
-
* Roles must be a non-empty subset of the
|
|
34
|
-
*
|
|
35
|
-
*
|
|
61
|
+
* Roles must be a non-empty subset of the roles the configured
|
|
62
|
+
* {@link AccessTokenRolePolicy} allows the owner to carry ( see
|
|
63
|
+
* `_allowed_roles` above - not necessarily the owner's literal `Role` list ).
|
|
64
|
+
* `expiresAt` null means the token never expires. The plaintext is returned
|
|
65
|
+
* once and never persisted - only its hash is stored.
|
|
36
66
|
*
|
|
37
67
|
* @param user - owner: {@link User} instance, numeric id or uuid
|
|
38
68
|
* @param name - human readable label
|
|
39
|
-
* @param roles - roles carried by the token, subset of the
|
|
69
|
+
* @param roles - roles carried by the token, subset of what the configured
|
|
70
|
+
* {@link AccessTokenRolePolicy} allows the owner
|
|
40
71
|
* @param expiresAt - absolute expiration, or null for a token that never expires
|
|
72
|
+
* @param profile - role the token is pinned to, from what the configured
|
|
73
|
+
* {@link AccessTokenRolePolicy} offers the owner; omitted
|
|
74
|
+
* leaves the token unpinned ( legacy behaviour )
|
|
41
75
|
*/
|
|
42
|
-
export declare function createToken(user: User | number | string, name: string, roles: string[], expiresAt: DateTime | null): Promise<{
|
|
76
|
+
export declare function createToken(user: User | number | string, name: string, roles: string[], expiresAt: DateTime | null, profile?: string): Promise<{
|
|
43
77
|
Token: AccessToken;
|
|
44
78
|
Plaintext: string;
|
|
45
79
|
}>;
|
|
@@ -50,7 +84,8 @@ export declare function createToken(user: User | number | string, name: string,
|
|
|
50
84
|
*/
|
|
51
85
|
export declare function deleteToken(token: AccessToken | string): Promise<void>;
|
|
52
86
|
/**
|
|
53
|
-
* Adds a role to a token. The role must be
|
|
87
|
+
* Adds a role to a token. The role must be allowed for the token owner by the
|
|
88
|
+
* configured {@link AccessTokenRolePolicy}.
|
|
54
89
|
*
|
|
55
90
|
* @param token - {@link AccessToken} instance or its uuid
|
|
56
91
|
* @param role - role name to grant
|
|
@@ -78,7 +113,8 @@ export interface ITokenValidationResult {
|
|
|
78
113
|
User: User;
|
|
79
114
|
Token: AccessToken;
|
|
80
115
|
/**
|
|
81
|
-
* Token roles
|
|
116
|
+
* Token roles the configured {@link AccessTokenRolePolicy} still allows for
|
|
117
|
+
* the owner. Permission checks run with these.
|
|
82
118
|
*/
|
|
83
119
|
EffectiveRoles: string[];
|
|
84
120
|
}
|
package/lib/mjs/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["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AMG;AACH,wBAAsB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAcpG;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAmBrG;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,WAAW,CAAC;IAEnB;;;OAGG;IACH,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAyDtF;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAU3D;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAS3F"}
|
package/lib/mjs/actions.js
CHANGED
|
@@ -5,8 +5,9 @@ import { _chain, _check_arg, _tap, _trim, _non_empty, _non_nil, _max_length } fr
|
|
|
5
5
|
import { _service } from '@spinajs/configuration';
|
|
6
6
|
import { _ev } from '@spinajs/queue';
|
|
7
7
|
import { ErrorCode } from '@spinajs/exceptions';
|
|
8
|
+
import { DI } from '@spinajs/di';
|
|
8
9
|
import { AccessToken } from './models/AccessToken.js';
|
|
9
|
-
import { AccessTokenGenerationProvider } from './interfaces.js';
|
|
10
|
+
import { AccessTokenGenerationProvider, AccessTokenRolePolicy } from './interfaces.js';
|
|
10
11
|
import { AccessTokenCreated, AccessTokenDeleted, AccessTokenRoleGranted, AccessTokenRoleRevoked } from './events/index.js';
|
|
11
12
|
/**
|
|
12
13
|
* Failure codes carried by every {@link ErrorCode} this module throws.
|
|
@@ -63,37 +64,101 @@ function _token_ev(event, ...args) {
|
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
67
|
+
* Roles the configured {@link AccessTokenRolePolicy} lets `owner` put on a
|
|
68
|
+
* token. Resolved per call rather than cached, so a policy that answers from
|
|
69
|
+
* live state ( the owner's current roles, the application's grants ) is not
|
|
70
|
+
* frozen at boot.
|
|
71
|
+
*
|
|
72
|
+
* Filters the policy's answer down to role names `accesscontrol` actually
|
|
73
|
+
* knows about ( i.e. present in `ac.getGrants()` ). A policy is arbitrary
|
|
74
|
+
* application code and may return a typo'd or stale role name; without this
|
|
75
|
+
* filter such a name would be offered by `GET user/tokens/roles`, accepted by
|
|
76
|
+
* `createToken`/`grantTokenRole` onto a token, and then make every request
|
|
77
|
+
* that token authenticates 500 - `checkRoutePermission` calls
|
|
78
|
+
* `ac.can(roles)[permission](resource)`, and `accesscontrol` throws
|
|
79
|
+
* `AccessControlError` for a role absent from its grants map. A role that
|
|
80
|
+
* grants nothing must never be offered or authorised in the first place.
|
|
81
|
+
*
|
|
82
|
+
* Filters with `Object.hasOwn`, not `Boolean(grants[r])`: `getGrants()` returns a plain
|
|
83
|
+
* object, so `grants['constructor']`, `['toString']`, `['valueOf']`, `['hasOwnProperty']`
|
|
84
|
+
* and `['__proto__']` all resolve truthy through the prototype chain even though no role by
|
|
85
|
+
* that name was ever registered. A policy returning `'constructor'` would otherwise survive
|
|
86
|
+
* this filter, get offered by `GET user/tokens/roles`, and be mintable onto a token.
|
|
87
|
+
*/
|
|
88
|
+
export async function _allowed_roles(owner, profile) {
|
|
89
|
+
const policy = await _service('rbac.token.rolePolicy', AccessTokenRolePolicy)();
|
|
90
|
+
const allowed = await policy.allowedRoles(owner, profile);
|
|
91
|
+
const ac = DI.get('AccessControl');
|
|
92
|
+
const grants = ac.getGrants();
|
|
93
|
+
return allowed.filter((r) => Object.hasOwn(grants, r));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Profiles the configured {@link AccessTokenRolePolicy} lets `owner` pin a
|
|
97
|
+
* token to. Same live-resolution rationale as `_allowed_roles`.
|
|
98
|
+
*/
|
|
99
|
+
export async function _allowed_profiles(owner) {
|
|
100
|
+
const policy = await _service('rbac.token.rolePolicy', AccessTokenRolePolicy)();
|
|
101
|
+
return policy.allowedProfiles(owner);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Ensures `profile` is one the configured policy lets `owner` pin a token to.
|
|
68
105
|
*/
|
|
69
|
-
function
|
|
70
|
-
const
|
|
106
|
+
async function _assert_profile(owner, profile) {
|
|
107
|
+
const allowed = await _allowed_profiles(owner);
|
|
108
|
+
if (!allowed.includes(profile)) {
|
|
109
|
+
throw new ErrorCode(E_TOKEN_CODES.E_TOKEN_ROLE_NOT_ALLOWED, `Owner may not pin a token to profile: ${profile}`, { roles: [profile] });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Ensures every role in `roles` is one the configured policy allows for
|
|
114
|
+
* `owner`. Deliberately not "one the owner literally holds" - a policy may
|
|
115
|
+
* permit roles beyond the owner's own `Role` list, or withhold ones on it;
|
|
116
|
+
* that flexibility is the entire point of the policy seam.
|
|
117
|
+
*
|
|
118
|
+
* With `profile` given the question is asked relative to that profile, which a
|
|
119
|
+
* policy may answer more narrowly than the owner-wide union.
|
|
120
|
+
*/
|
|
121
|
+
async function _assert_roles_subset(owner, roles, profile) {
|
|
122
|
+
const allowed = await _allowed_roles(owner, profile);
|
|
123
|
+
const missing = roles.filter((r) => !allowed.includes(r));
|
|
71
124
|
if (missing.length !== 0) {
|
|
72
|
-
throw new ErrorCode(E_TOKEN_CODES.E_TOKEN_ROLE_NOT_ALLOWED, `Owner
|
|
125
|
+
throw new ErrorCode(E_TOKEN_CODES.E_TOKEN_ROLE_NOT_ALLOWED, `Owner may not put role(s) on a token: ${missing.join(', ')}`, { roles: missing });
|
|
73
126
|
}
|
|
74
127
|
}
|
|
75
128
|
/**
|
|
76
129
|
* Creates a new access token for a user.
|
|
77
130
|
*
|
|
78
|
-
* Roles must be a non-empty subset of the
|
|
79
|
-
*
|
|
80
|
-
*
|
|
131
|
+
* Roles must be a non-empty subset of the roles the configured
|
|
132
|
+
* {@link AccessTokenRolePolicy} allows the owner to carry ( see
|
|
133
|
+
* `_allowed_roles` above - not necessarily the owner's literal `Role` list ).
|
|
134
|
+
* `expiresAt` null means the token never expires. The plaintext is returned
|
|
135
|
+
* once and never persisted - only its hash is stored.
|
|
81
136
|
*
|
|
82
137
|
* @param user - owner: {@link User} instance, numeric id or uuid
|
|
83
138
|
* @param name - human readable label
|
|
84
|
-
* @param roles - roles carried by the token, subset of the
|
|
139
|
+
* @param roles - roles carried by the token, subset of what the configured
|
|
140
|
+
* {@link AccessTokenRolePolicy} allows the owner
|
|
85
141
|
* @param expiresAt - absolute expiration, or null for a token that never expires
|
|
142
|
+
* @param profile - role the token is pinned to, from what the configured
|
|
143
|
+
* {@link AccessTokenRolePolicy} offers the owner; omitted
|
|
144
|
+
* leaves the token unpinned ( legacy behaviour )
|
|
86
145
|
*/
|
|
87
|
-
export async function createToken(user, name, roles, expiresAt) {
|
|
146
|
+
export async function createToken(user, name, roles, expiresAt, profile) {
|
|
88
147
|
name = _check_arg(_trim(), _non_empty(), _max_length(128))(name, 'name');
|
|
89
148
|
roles = _check_arg(_non_nil(), _non_empty())(roles, 'roles');
|
|
90
149
|
const generator = await _service('rbac.token.generation', AccessTokenGenerationProvider)();
|
|
91
150
|
const generated = await generator.generate();
|
|
92
|
-
return _chain(_owner(user), _tap(async (u) =>
|
|
151
|
+
return _chain(_owner(user), _tap(async (u) => {
|
|
152
|
+
if (profile) {
|
|
153
|
+
await _assert_profile(u, profile);
|
|
154
|
+
}
|
|
155
|
+
await _assert_roles_subset(u, roles, profile);
|
|
156
|
+
}), async (u) => {
|
|
93
157
|
const token = new AccessToken({
|
|
94
158
|
Name: name,
|
|
95
159
|
Token: generated.Hash,
|
|
96
160
|
Roles: _.uniq(roles),
|
|
161
|
+
Profile: profile ?? undefined,
|
|
97
162
|
// `ExpiresAt` is optional rather than nullable ( see the model ), so a
|
|
98
163
|
// "never expires" token leaves the property unset instead of holding null.
|
|
99
164
|
ExpiresAt: expiresAt ?? undefined,
|
|
@@ -112,7 +177,8 @@ export async function deleteToken(token) {
|
|
|
112
177
|
return _chain(_token(token), _tap((t) => t.destroy()), _token_ev(AccessTokenDeleted), () => undefined);
|
|
113
178
|
}
|
|
114
179
|
/**
|
|
115
|
-
* Adds a role to a token. The role must be
|
|
180
|
+
* Adds a role to a token. The role must be allowed for the token owner by the
|
|
181
|
+
* configured {@link AccessTokenRolePolicy}.
|
|
116
182
|
*
|
|
117
183
|
* @param token - {@link AccessToken} instance or its uuid
|
|
118
184
|
* @param role - role name to grant
|
|
@@ -121,7 +187,7 @@ export async function grantTokenRole(token, role) {
|
|
|
121
187
|
role = _check_arg(_trim(), _non_empty())(role, 'role');
|
|
122
188
|
return _chain(_token(token), _tap(async (t) => {
|
|
123
189
|
const owner = await _owner(t.user_id)();
|
|
124
|
-
_assert_roles_subset(owner, [role]);
|
|
190
|
+
await _assert_roles_subset(owner, [role], t.Profile);
|
|
125
191
|
t.Roles = _.uniq([...t.Roles, role]);
|
|
126
192
|
await t.update();
|
|
127
193
|
}), _token_ev(AccessTokenRoleGranted, role));
|
|
@@ -198,10 +264,21 @@ export async function validateToken(plaintext) {
|
|
|
198
264
|
if (!owner || !owner.IsActive || owner.DeletedAt || owner.IsBanned) {
|
|
199
265
|
throw new ErrorCode(E_TOKEN_CODES.E_TOKEN_OWNER_INVALID, 'Access token owner is not allowed to authenticate', { token: token.Uuid });
|
|
200
266
|
}
|
|
201
|
-
//
|
|
202
|
-
//
|
|
267
|
+
// a profile token whose owner no longer passes the profile policy (role
|
|
268
|
+
// revoked, policy tightened) authorises nothing - same immediacy rule as
|
|
269
|
+
// the role re-intersection below
|
|
270
|
+
if (token.Profile) {
|
|
271
|
+
const profiles = await _allowed_profiles(owner);
|
|
272
|
+
if (!profiles.includes(token.Profile)) {
|
|
273
|
+
throw new ErrorCode(E_TOKEN_CODES.E_TOKEN_ROLE_NOT_ALLOWED, 'Access token profile is no longer allowed for its owner', { token: token.Uuid });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// roles are re-checked against the policy on every request rather than
|
|
277
|
+
// trusted from the row: a role the owner loses - or one an application's
|
|
278
|
+
// policy stops allowing - must take effect immediately, without having to
|
|
203
279
|
// hunt down every token that still carries it
|
|
204
|
-
const
|
|
280
|
+
const allowed = await _allowed_roles(owner, token.Profile);
|
|
281
|
+
const effective = token.Roles.filter((r) => allowed.includes(r));
|
|
205
282
|
if (effective.length === 0) {
|
|
206
283
|
throw new ErrorCode(E_TOKEN_CODES.E_TOKEN_ROLE_NOT_ALLOWED, 'Access token has no effective roles', { token: token.Uuid });
|
|
207
284
|
}
|
package/lib/mjs/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACnG,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO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EAAE,qCAAqC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5H,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,CAAC;AAClE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,2EAA2E;IAC3E,iEAAiE;IACjE,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAErG,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC;AACxB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAkB,EAAE,eAAuB;IAC1E,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC;IAE3B,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;QACnF,OAAO;IACT,CAAC;IAED,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC;IACvB,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -46,7 +46,7 @@ CreateToken = __decorate([
|
|
|
46
46
|
Command('rbac:token-create', 'Creates an access token for a user'),
|
|
47
47
|
Argument('userIdOrUuid', true, 'numeric id or uuid of the owner'),
|
|
48
48
|
Option('-n, --name <name>', true, 'token label'),
|
|
49
|
-
Option('-r, --roles <roles>', true, 'token roles, comma separated, must be
|
|
49
|
+
Option('-r, --roles <roles>', true, 'token roles, comma separated, must be allowed for the owner by the configured role policy'),
|
|
50
50
|
Option('-e, --expires <expires>', false, 'ISO expiration instant; omit for a token that never expires')
|
|
51
51
|
], CreateToken);
|
|
52
52
|
export { CreateToken };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateToken.js","sourceRoot":"","sources":["../../../src/cli/CreateToken.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAarC,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;IAIlC,KAAK,CAAC,OAAO,CAAC,YAAoB,EAAE,OAA4B;QACrE,IAAI,CAAC;YACH,wEAAwE;YACxE,0EAA0E;YAC1E,yEAAyE;YACzE,yCAAyC;YACzC,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACvH,IAAI,SAAS,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;gBACpC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,4BAA4B,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;gBAC9D,OAAO;YACT,CAAC;YAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK;iBACxB,KAAK,CAAC,GAAG,CAAC;iBACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;iBACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CA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,CAAC,mDAAmD,SAAS,EAAE,CAAC,CAAC;QACnF,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,+BAAgC,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF,CAAA;AA7BW;IADT,MAAM,CAAC,iBAAiB,CAAC;8BACX,GAAG;wCAAC;AAFR,WAAW;IALvB,OAAO,CAAC,mBAAmB,EAAE,oCAAoC,CAAC;IAClE,QAAQ,CAAC,cAAc,EAAE,IAAI,EAAE,iCAAiC,CAAC;IACjE,MAAM,CAAC,mBAAmB,EAAE,IAAI,EAAE,aAAa,CAAC;IAChD,MAAM,CAAC,qBAAqB,EAAE,IAAI,EAAE,2FAA2F,CAAC;IAChI,MAAM,CAAC,yBAAyB,EAAE,KAAK,EAAE,6DAA6D,CAAC;GAC3F,WAAW,CA+BvB"}
|
|
@@ -28,7 +28,7 @@ __decorate([
|
|
|
28
28
|
GrantTokenRole = __decorate([
|
|
29
29
|
Command('rbac:token-grant', 'Grants a role to an access token'),
|
|
30
30
|
Argument('uuid', true, 'token uuid'),
|
|
31
|
-
Argument('role', true, 'role to grant, must be
|
|
31
|
+
Argument('role', true, 'role to grant, must be allowed for the token owner by the configured role policy')
|
|
32
32
|
], GrantTokenRole);
|
|
33
33
|
export { GrantTokenRole };
|
|
34
34
|
//# sourceMappingURL=GrantTokenRole.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GrantTokenRole.js","sourceRoot":"","sources":["../../../src/cli/GrantTokenRole.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAKxC,IAAM,cAAc,GAApB,MAAM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,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,IAAI,aAAa,IAAI,KAAM,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAChG,CAAC;IACH,CAAC;CACF,CAAA;AAVW;IADT,MAAM,CAAC,iBAAiB,CAAC;8BACX,GAAG;2CAAC;AAFR,cAAc;IAH1B,OAAO,CAAC,kBAAkB,EAAE,kCAAkC,CAAC;IAC/D,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,kFAAkF,CAAC;GAC9F,cAAc,CAY1B"}
|
|
@@ -30,6 +30,23 @@ declare const rbacHttpToken: {
|
|
|
30
30
|
generation: {
|
|
31
31
|
service: string;
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Decides which roles an owner may put on a token. Swap for your own
|
|
35
|
+
* implementation of AccessTokenRolePolicy registered under this name.
|
|
36
|
+
*/
|
|
37
|
+
rolePolicy: {
|
|
38
|
+
service: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Role name patterns for a custom AccessTokenRolePolicy to consult - not
|
|
42
|
+
* read by anything shipped in this package, including the default
|
|
43
|
+
* `OwnRolesTokenRolePolicy`. An exact name, or a name ending in `.*`
|
|
44
|
+
* matching that prefix and everything under it; matching is implemented
|
|
45
|
+
* by `_role_excluded(role, patterns)` in `src/role-policy.ts`. Empty by
|
|
46
|
+
* default: this package has no opinion about which of an application's
|
|
47
|
+
* roles are meaningful to an API caller.
|
|
48
|
+
*/
|
|
49
|
+
excludedRoles: string[];
|
|
33
50
|
/**
|
|
34
51
|
* Stable plaintext prefix - lets secret scanners recognise leaked tokens.
|
|
35
52
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rbac-http-token.d.ts","sourceRoot":"","sources":["../../../src/config/rbac-http-token.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,aAAa;IACjB,MAAM;QACJ,IAAI;YAIF,GAAG;YACH,WAAW;;;IAqBf,KAAK;QAKH,OAAO;YACL,kBAAkB;gBAAI,UAAU;;YAChC,kBAAkB;gBAAI,UAAU;;YAChC,sBAAsB;gBAAI,UAAU;;YACpC,sBAAsB;gBAAI,UAAU;;;;IAGxC,IAAI;QACF,KAAK;YACH;;;eAGG;YACH,UAAU;gBACR,OAAO;;YAGT;;eAEG;YACH,MAAM;YAEN;;eAEG;YACH,MAAM;YAEN;;eAEG;YACH,UAAU;YAEV;;eAEG;YACH,sBAAsB;;QAExB,MAAM;YACJ,IAAI;gBACF,aAAa;oBAAI,YAAY;oBAAS,UAAU;oBAAS,YAAY;oBAAS,YAAY;;;YAa5F,aAAa;gBACX,aAAa;oBAAI,YAAY;oBAAS,UAAU;oBAAS,YAAY;oBAAS,YAAY;;;;;CAIjG,CAAC;eAEa,aAAa"}
|
|
1
|
+
{"version":3,"file":"rbac-http-token.d.ts","sourceRoot":"","sources":["../../../src/config/rbac-http-token.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,aAAa;IACjB,MAAM;QACJ,IAAI;YAIF,GAAG;YACH,WAAW;;;IAqBf,KAAK;QAKH,OAAO;YACL,kBAAkB;gBAAI,UAAU;;YAChC,kBAAkB;gBAAI,UAAU;;YAChC,sBAAsB;gBAAI,UAAU;;YACpC,sBAAsB;gBAAI,UAAU;;;;IAGxC,IAAI;QACF,KAAK;YACH;;;eAGG;YACH,UAAU;gBACR,OAAO;;YAGT;;;eAGG;YACH,UAAU;gBACR,OAAO;;YAGT;;;;;;;;eAQG;YACH,aAAa,EAAQ,MAAM,EAAE;YAE7B;;eAEG;YACH,MAAM;YAEN;;eAEG;YACH,MAAM;YAEN;;eAEG;YACH,UAAU;YAEV;;eAEG;YACH,sBAAsB;;QAExB,MAAM;YACJ,IAAI;gBACF,aAAa;oBAAI,YAAY;oBAAS,UAAU;oBAAS,YAAY;oBAAS,YAAY;;;YAa5F,aAAa;gBACX,aAAa;oBAAI,YAAY;oBAAS,UAAU;oBAAS,YAAY;oBAAS,YAAY;;;;;CAIjG,CAAC;eAEa,aAAa"}
|
|
@@ -55,6 +55,23 @@ const rbacHttpToken = {
|
|
|
55
55
|
generation: {
|
|
56
56
|
service: 'SecureRandomTokenProvider',
|
|
57
57
|
},
|
|
58
|
+
/**
|
|
59
|
+
* Decides which roles an owner may put on a token. Swap for your own
|
|
60
|
+
* implementation of AccessTokenRolePolicy registered under this name.
|
|
61
|
+
*/
|
|
62
|
+
rolePolicy: {
|
|
63
|
+
service: 'OwnRolesTokenRolePolicy',
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* Role name patterns for a custom AccessTokenRolePolicy to consult - not
|
|
67
|
+
* read by anything shipped in this package, including the default
|
|
68
|
+
* `OwnRolesTokenRolePolicy`. An exact name, or a name ending in `.*`
|
|
69
|
+
* matching that prefix and everything under it; matching is implemented
|
|
70
|
+
* by `_role_excluded(role, patterns)` in `src/role-policy.ts`. Empty by
|
|
71
|
+
* default: this package has no opinion about which of an application's
|
|
72
|
+
* roles are meaningful to an API caller.
|
|
73
|
+
*/
|
|
74
|
+
excludedRoles: [],
|
|
58
75
|
/**
|
|
59
76
|
* Stable plaintext prefix - lets secret scanners recognise leaked tokens.
|
|
60
77
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rbac-http-token.js","sourceRoot":"","sources":["../../../src/config/rbac-http-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAY;IACvB,MAAM,UAAU,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;IACjD,OAAO;QACL,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,UAAU,EAAE,iBAAiB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAA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;eAGG;YACH,UAAU,EAAE;gBACV,OAAO,EAAE,yBAAyB;aACnC;YAED;;;;;;;;eAQG;YACH,aAAa,EAAE,EAAc;YAE7B;;eAEG;YACH,MAAM,EAAE,MAAM;YAEd;;eAEG;YACH,MAAM,EAAE,EAAE;YAEV;;eAEG;YACH,UAAU,EAAE,WAAW;YAEvB;;eAEG;YACH,sBAAsB,EAAE,EAAE;SAC3B;QACD,MAAM,EAAE;YACN,IAAI,EAAE;gBACJ,aAAa,EAAE,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE;aACpG;YAED,yEAAyE;YACzE,EAAE;YACF,wEAAwE;YACxE,uEAAuE;YACvE,wEAAwE;YACxE,wEAAwE;YACxE,wEAAwE;YACxE,wEAAwE;YACxE,uEAAuE;YACvE,+DAA+D;YAC/D,aAAa,EAAE;gBACb,aAAa,EAAE,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE;aACpG;SACF;KACF;CACF,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -39,6 +39,34 @@ import { CreateTokenDto } from '../dto/create-token-dto.js';
|
|
|
39
39
|
* @tags AccessTokens
|
|
40
40
|
*/
|
|
41
41
|
export declare class AccessTokenController extends BaseController {
|
|
42
|
+
/**
|
|
43
|
+
* Roles that may be put on a new token
|
|
44
|
+
* Answers from the configured AccessTokenRolePolicy - the same source
|
|
45
|
+
* `POST user/tokens` validates against, so a client can never be offered a
|
|
46
|
+
* role the create call would then refuse.
|
|
47
|
+
*
|
|
48
|
+
* With `profile` given the answer is relative to that profile, which a policy
|
|
49
|
+
* may narrow below the owner-wide union - the picker must ask with the profile
|
|
50
|
+
* the user has selected, or it will keep offering roles the pinned create call
|
|
51
|
+
* then refuses. Without the param the answer is what this route always gave.
|
|
52
|
+
* @security cookieAuth
|
|
53
|
+
* @param profile Optional profile ( root role ) the roles are asked for
|
|
54
|
+
* @response 200 Roles the caller may put on a token
|
|
55
|
+
* @response 401 Unauthorized - valid session required
|
|
56
|
+
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
57
|
+
*/
|
|
58
|
+
roles(user: UserModel, profile?: string): Promise<Ok<unknown>>;
|
|
59
|
+
/**
|
|
60
|
+
* Profiles the caller may pin a new token to
|
|
61
|
+
* Answers from the configured AccessTokenRolePolicy - the same source
|
|
62
|
+
* `POST user/tokens` validates `Profile` against. Empty for applications that
|
|
63
|
+
* did not opt into profile tokens: the shipped default policy offers none.
|
|
64
|
+
* @security cookieAuth
|
|
65
|
+
* @response 200 Profiles the caller may pin a token to
|
|
66
|
+
* @response 401 Unauthorized - valid session required
|
|
67
|
+
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
68
|
+
*/
|
|
69
|
+
profiles(user: UserModel): Promise<Ok<unknown>>;
|
|
42
70
|
/**
|
|
43
71
|
* List own access tokens
|
|
44
72
|
* Hashes are never returned - `Token` is `@Hidden()` on the model, so the
|
|
@@ -52,10 +80,14 @@ export declare class AccessTokenController extends BaseController {
|
|
|
52
80
|
/**
|
|
53
81
|
* Create an access token
|
|
54
82
|
* The plaintext appears in this response only and cannot be retrieved again.
|
|
55
|
-
* Roles must be a subset of the
|
|
83
|
+
* Roles must be a subset of what the configured AccessTokenRolePolicy allows
|
|
84
|
+
* the caller - the same set `GET user/tokens/roles` reports. An optional
|
|
85
|
+
* `Profile` pins the token to one of the profiles `GET user/tokens/profiles`
|
|
86
|
+
* reports, and narrows the role check to that profile; omitted, the token is
|
|
87
|
+
* scoped by the union of its roles as before.
|
|
56
88
|
* @security cookieAuth
|
|
57
89
|
* @response 200 Token created, `Plaintext` returned once
|
|
58
|
-
* @response 400 Requested roles are not
|
|
90
|
+
* @response 400 Requested roles or profile are not allowed for the caller by the configured role policy
|
|
59
91
|
* @response 401 Unauthorized - valid session required
|
|
60
92
|
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
61
93
|
*/
|
|
@@ -72,13 +104,14 @@ export declare class AccessTokenController extends BaseController {
|
|
|
72
104
|
delete(user: UserModel, uuid: string): Promise<Ok | NotFound>;
|
|
73
105
|
/**
|
|
74
106
|
* Grant a role to an own token
|
|
75
|
-
* The role must be
|
|
76
|
-
*
|
|
107
|
+
* The role must be allowed for the caller by the configured
|
|
108
|
+
* AccessTokenRolePolicy - a token can never carry more than the policy
|
|
109
|
+
* permits its owner.
|
|
77
110
|
* @security cookieAuth
|
|
78
111
|
* @param uuid Public identifier of the token
|
|
79
112
|
* @param role Role name to grant
|
|
80
113
|
* @response 200 Updated token
|
|
81
|
-
* @response 400 Role is not
|
|
114
|
+
* @response 400 Role is not allowed for the caller by the configured role policy
|
|
82
115
|
* @response 401 Unauthorized - valid session required
|
|
83
116
|
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
84
117
|
* @response 404 No such token for this user
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessTokenController.d.ts","sourceRoot":"","sources":["../../../src/controllers/AccessTokenController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAA4B,QAAQ,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"AccessTokenController.d.ts","sourceRoot":"","sources":["../../../src/controllers/AccessTokenController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAA4B,QAAQ,EAAE,EAAE,EAAmC,MAAM,eAAe,CAAC;AAC5I,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,eAAe,CAAC;AAKlD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAI5D;;;;;;;;;;;;;;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AAC,CAE7E;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAE5D;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,CAMpD;CACF"}
|
|
@@ -10,13 +10,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
|
-
import { BadRequestResponse, BaseController, BasePath, Body, Del, Get, NotFound, Ok, Param, Policy, Post, Put } from '@spinajs/http';
|
|
13
|
+
import { BadRequestResponse, BaseController, BasePath, Body, Del, Get, NotFound, Ok, Param, Policy, Post, Put, Query } from '@spinajs/http';
|
|
14
14
|
import { User as UserModel } from '@spinajs/rbac';
|
|
15
15
|
import { Permission, Resource, User } from '@spinajs/rbac-http';
|
|
16
16
|
import { ErrorCode } from '@spinajs/exceptions';
|
|
17
17
|
import { DateTime } from 'luxon';
|
|
18
18
|
import { AccessToken } from '../models/AccessToken.js';
|
|
19
|
-
import { E_TOKEN_CODES, createToken, deleteToken, grantTokenRole, revokeTokenRole } from '../actions.js';
|
|
19
|
+
import { E_TOKEN_CODES, _allowed_profiles, _allowed_roles, createToken, deleteToken, grantTokenRole, revokeTokenRole } from '../actions.js';
|
|
20
20
|
import { CreateTokenDto } from '../dto/create-token-dto.js';
|
|
21
21
|
import { NoTokenAuthPolicy } from '../policies/NoTokenAuthPolicy.js';
|
|
22
22
|
import { NoImpersonationPolicy } from '../policies/NoImpersonationPolicy.js';
|
|
@@ -57,6 +57,38 @@ import { NoImpersonationPolicy } from '../policies/NoImpersonationPolicy.js';
|
|
|
57
57
|
* @tags AccessTokens
|
|
58
58
|
*/
|
|
59
59
|
let AccessTokenController = class AccessTokenController extends BaseController {
|
|
60
|
+
/**
|
|
61
|
+
* Roles that may be put on a new token
|
|
62
|
+
* Answers from the configured AccessTokenRolePolicy - the same source
|
|
63
|
+
* `POST user/tokens` validates against, so a client can never be offered a
|
|
64
|
+
* role the create call would then refuse.
|
|
65
|
+
*
|
|
66
|
+
* With `profile` given the answer is relative to that profile, which a policy
|
|
67
|
+
* may narrow below the owner-wide union - the picker must ask with the profile
|
|
68
|
+
* the user has selected, or it will keep offering roles the pinned create call
|
|
69
|
+
* then refuses. Without the param the answer is what this route always gave.
|
|
70
|
+
* @security cookieAuth
|
|
71
|
+
* @param profile Optional profile ( root role ) the roles are asked for
|
|
72
|
+
* @response 200 Roles the caller may put on a token
|
|
73
|
+
* @response 401 Unauthorized - valid session required
|
|
74
|
+
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
75
|
+
*/
|
|
76
|
+
async roles(user, profile) {
|
|
77
|
+
return new Ok({ Roles: await _allowed_roles(user, profile) });
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Profiles the caller may pin a new token to
|
|
81
|
+
* Answers from the configured AccessTokenRolePolicy - the same source
|
|
82
|
+
* `POST user/tokens` validates `Profile` against. Empty for applications that
|
|
83
|
+
* did not opt into profile tokens: the shipped default policy offers none.
|
|
84
|
+
* @security cookieAuth
|
|
85
|
+
* @response 200 Profiles the caller may pin a token to
|
|
86
|
+
* @response 401 Unauthorized - valid session required
|
|
87
|
+
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
88
|
+
*/
|
|
89
|
+
async profiles(user) {
|
|
90
|
+
return new Ok({ Profiles: await _allowed_profiles(user) });
|
|
91
|
+
}
|
|
60
92
|
/**
|
|
61
93
|
* List own access tokens
|
|
62
94
|
* Hashes are never returned - `Token` is `@Hidden()` on the model, so the
|
|
@@ -73,17 +105,21 @@ let AccessTokenController = class AccessTokenController extends BaseController {
|
|
|
73
105
|
/**
|
|
74
106
|
* Create an access token
|
|
75
107
|
* The plaintext appears in this response only and cannot be retrieved again.
|
|
76
|
-
* Roles must be a subset of the
|
|
108
|
+
* Roles must be a subset of what the configured AccessTokenRolePolicy allows
|
|
109
|
+
* the caller - the same set `GET user/tokens/roles` reports. An optional
|
|
110
|
+
* `Profile` pins the token to one of the profiles `GET user/tokens/profiles`
|
|
111
|
+
* reports, and narrows the role check to that profile; omitted, the token is
|
|
112
|
+
* scoped by the union of its roles as before.
|
|
77
113
|
* @security cookieAuth
|
|
78
114
|
* @response 200 Token created, `Plaintext` returned once
|
|
79
|
-
* @response 400 Requested roles are not
|
|
115
|
+
* @response 400 Requested roles or profile are not allowed for the caller by the configured role policy
|
|
80
116
|
* @response 401 Unauthorized - valid session required
|
|
81
117
|
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
82
118
|
*/
|
|
83
119
|
async create(user, dto) {
|
|
84
120
|
const expiresAt = dto.ExpiresAt ? DateTime.fromISO(dto.ExpiresAt) : null;
|
|
85
121
|
try {
|
|
86
|
-
const { Token, Plaintext } = await createToken(user, dto.Name, dto.Roles, expiresAt);
|
|
122
|
+
const { Token, Plaintext } = await createToken(user, dto.Name, dto.Roles, expiresAt, dto.Profile);
|
|
87
123
|
return new Ok({ Token: this.toWire(Token), Plaintext }, { Headers: [{ Name: 'Cache-Control', Value: 'no-store' }] });
|
|
88
124
|
}
|
|
89
125
|
catch (err) {
|
|
@@ -109,13 +145,14 @@ let AccessTokenController = class AccessTokenController extends BaseController {
|
|
|
109
145
|
}
|
|
110
146
|
/**
|
|
111
147
|
* Grant a role to an own token
|
|
112
|
-
* The role must be
|
|
113
|
-
*
|
|
148
|
+
* The role must be allowed for the caller by the configured
|
|
149
|
+
* AccessTokenRolePolicy - a token can never carry more than the policy
|
|
150
|
+
* permits its owner.
|
|
114
151
|
* @security cookieAuth
|
|
115
152
|
* @param uuid Public identifier of the token
|
|
116
153
|
* @param role Role name to grant
|
|
117
154
|
* @response 200 Updated token
|
|
118
|
-
* @response 400 Role is not
|
|
155
|
+
* @response 400 Role is not allowed for the caller by the configured role policy
|
|
119
156
|
* @response 401 Unauthorized - valid session required
|
|
120
157
|
* @response 403 Forbidden - access tokens cannot be used on this route
|
|
121
158
|
* @response 404 No such token for this user
|
|
@@ -206,6 +243,23 @@ let AccessTokenController = class AccessTokenController extends BaseController {
|
|
|
206
243
|
throw err;
|
|
207
244
|
}
|
|
208
245
|
};
|
|
246
|
+
__decorate([
|
|
247
|
+
Get('tokens/roles'),
|
|
248
|
+
Permission(['readOwn']),
|
|
249
|
+
__param(0, User()),
|
|
250
|
+
__param(1, Query()),
|
|
251
|
+
__metadata("design:type", Function),
|
|
252
|
+
__metadata("design:paramtypes", [UserModel, String]),
|
|
253
|
+
__metadata("design:returntype", Promise)
|
|
254
|
+
], AccessTokenController.prototype, "roles", null);
|
|
255
|
+
__decorate([
|
|
256
|
+
Get('tokens/profiles'),
|
|
257
|
+
Permission(['readOwn']),
|
|
258
|
+
__param(0, User()),
|
|
259
|
+
__metadata("design:type", Function),
|
|
260
|
+
__metadata("design:paramtypes", [UserModel]),
|
|
261
|
+
__metadata("design:returntype", Promise)
|
|
262
|
+
], AccessTokenController.prototype, "profiles", null);
|
|
209
263
|
__decorate([
|
|
210
264
|
Get('tokens'),
|
|
211
265
|
Permission(['readOwn']),
|