@mastra/auth-studio 1.3.3 → 1.3.4-alpha.0
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/CHANGELOG.md +8 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/permissions.generated.d.ts +12 -2
- package/dist/_types/@internal_auth/dist/types/index.d.ts +6 -2
- package/dist/index.cjs +125 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +125 -108
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,112 +1,24 @@
|
|
|
1
1
|
import { createHash } from "crypto";
|
|
2
|
-
//#region ../../packages/_internals/auth/dist/
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Compound resource keys that expand to a set of per-family resources.
|
|
10
|
-
* A granted `stored:<action>` is treated as matching any `stored-<family>:<action>`
|
|
11
|
-
* (and `stored:*` matches any `stored-<family>:*`).
|
|
12
|
-
*/
|
|
13
|
-
const RESOURCE_EXPANSIONS = { stored: [
|
|
14
|
-
"stored-agents",
|
|
15
|
-
"stored-mcp-clients",
|
|
16
|
-
"stored-prompt-blocks",
|
|
17
|
-
"stored-scorers",
|
|
18
|
-
"stored-skills",
|
|
19
|
-
"stored-workspaces"
|
|
20
|
-
] };
|
|
21
|
-
/**
|
|
22
|
-
* Check if a permission matches (including wildcard support).
|
|
23
|
-
*
|
|
24
|
-
* Permission format: `{resource}:{action}[:{resource-id}]`
|
|
25
|
-
*
|
|
26
|
-
* Examples:
|
|
27
|
-
* - `*` matches everything
|
|
28
|
-
* - `agents:*` matches `agents:read`, `agents:read:my-agent`
|
|
29
|
-
* - `*:read` matches `agents:read`, `workflows:read` (action across all resources)
|
|
30
|
-
* - `agents:read` matches `agents:read`, `agents:read:my-agent`
|
|
31
|
-
* - `agents:read:my-agent` matches only `agents:read:my-agent`
|
|
32
|
-
* - `agents:*:my-agent` matches `agents:read:my-agent`, `agents:write:my-agent`
|
|
33
|
-
*
|
|
34
|
-
* @param userPermission - Permission the user has
|
|
35
|
-
* @param requiredPermission - Permission being checked
|
|
36
|
-
* @returns True if permission matches
|
|
37
|
-
*/
|
|
38
|
-
function matchesPermission(userPermission, requiredPermission) {
|
|
39
|
-
if (userPermission === "*") return true;
|
|
40
|
-
const grantedParts = userPermission.split(":");
|
|
41
|
-
const requiredParts = requiredPermission.split(":");
|
|
42
|
-
const expandedFamilies = RESOURCE_EXPANSIONS[grantedParts[0] ?? ""];
|
|
43
|
-
if (expandedFamilies && expandedFamilies.includes(requiredParts[0] ?? "")) return matchesPermission([requiredParts[0], ...grantedParts.slice(1)].join(":"), requiredPermission);
|
|
44
|
-
if (grantedParts.length < 2 || requiredParts.length < 2) return userPermission === requiredPermission;
|
|
45
|
-
const [grantedResource, grantedAction, grantedId] = grantedParts;
|
|
46
|
-
const [requiredResource, requiredAction, requiredId] = requiredParts;
|
|
47
|
-
if (grantedResource === "*") {
|
|
48
|
-
if (grantedAction === "*") {
|
|
49
|
-
if (grantedId === void 0) return true;
|
|
50
|
-
return grantedId === requiredId;
|
|
51
|
-
}
|
|
52
|
-
if (grantedAction !== requiredAction) return false;
|
|
53
|
-
if (grantedId === void 0) return true;
|
|
54
|
-
return grantedId === requiredId;
|
|
55
|
-
}
|
|
56
|
-
if (grantedResource !== requiredResource) return false;
|
|
57
|
-
if (grantedAction === "*") {
|
|
58
|
-
if (grantedId === void 0) return true;
|
|
59
|
-
return grantedId === requiredId;
|
|
60
|
-
}
|
|
61
|
-
if (grantedAction !== requiredAction) return false;
|
|
62
|
-
if (grantedId === void 0) return true;
|
|
63
|
-
return grantedId === requiredId;
|
|
2
|
+
//#region ../../packages/_internals/auth/dist/types/index.js
|
|
3
|
+
function headerFromPlainObject(headers, name) {
|
|
4
|
+
const normalizedName = name.toLowerCase();
|
|
5
|
+
const matchingKey = Object.keys(headers).find((key) => key.toLowerCase() === normalizedName);
|
|
6
|
+
const value = matchingKey === void 0 ? void 0 : headers[matchingKey];
|
|
7
|
+
return Array.isArray(value) ? value[0] ?? null : value ?? null;
|
|
64
8
|
}
|
|
65
9
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* This function translates provider-defined roles (from WorkOS, Okta, etc.)
|
|
69
|
-
* to Mastra permissions using a configurable mapping.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const roleMapping = {
|
|
74
|
-
* "Engineering": ["agents:*", "workflows:*"],
|
|
75
|
-
* "Product": ["agents:read"],
|
|
76
|
-
* "_default": [],
|
|
77
|
-
* };
|
|
78
|
-
*
|
|
79
|
-
* // User has "Engineering" and "QA" roles
|
|
80
|
-
* const permissions = resolvePermissionsFromMapping(
|
|
81
|
-
* ["Engineering", "QA"],
|
|
82
|
-
* roleMapping
|
|
83
|
-
* );
|
|
84
|
-
* // Result: ["agents:*", "workflows:*"] (QA is unmapped, gets _default)
|
|
85
|
-
* ```
|
|
86
|
-
*
|
|
87
|
-
* @param roles - User's roles from the identity provider
|
|
88
|
-
* @param mapping - Role to permission mapping
|
|
89
|
-
* @returns Array of resolved permissions
|
|
10
|
+
* Read a request header across fetch, Hono, and Express-style request shapes.
|
|
11
|
+
* Must not throw when `headers` is a plain object (Express `IncomingHttpHeaders`).
|
|
90
12
|
*/
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return Array.from(permissions);
|
|
13
|
+
function getRequestHeader(request, name) {
|
|
14
|
+
if (request instanceof Request) return request.headers.get(name);
|
|
15
|
+
if (request.raw instanceof Request) return request.raw.headers.get(name);
|
|
16
|
+
const headers = request.headers;
|
|
17
|
+
if (headers instanceof Headers) return headers.get(name);
|
|
18
|
+
if (typeof request.header === "function") return request.header(name) ?? null;
|
|
19
|
+
if (headers && typeof headers === "object") return headerFromPlainObject(headers, name);
|
|
20
|
+
return null;
|
|
100
21
|
}
|
|
101
|
-
/**
|
|
102
|
-
* @mastra/core/auth/ee
|
|
103
|
-
*
|
|
104
|
-
* Enterprise authentication capabilities for Mastra.
|
|
105
|
-
* This code is licensed under the Mastra Enterprise License - see ee/LICENSE.
|
|
106
|
-
*
|
|
107
|
-
* @license Mastra Enterprise License - see ee/LICENSE
|
|
108
|
-
* @packageDocumentation
|
|
109
|
-
*/
|
|
110
22
|
//#endregion
|
|
111
23
|
//#region ../../packages/_internal-core/dist/logger/index.js
|
|
112
24
|
const RegisteredLogger = {
|
|
@@ -315,11 +227,116 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
315
227
|
}
|
|
316
228
|
};
|
|
317
229
|
//#endregion
|
|
318
|
-
//#region
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
230
|
+
//#region ../../packages/_internals/auth/dist/ee-DXvSoTl7.js
|
|
231
|
+
/**
|
|
232
|
+
* FGA enforcement utility for checking fine-grained authorization.
|
|
233
|
+
*
|
|
234
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
235
|
+
*/
|
|
236
|
+
/**
|
|
237
|
+
* Compound resource keys that expand to a set of per-family resources.
|
|
238
|
+
* A granted `stored:<action>` is treated as matching any `stored-<family>:<action>`
|
|
239
|
+
* (and `stored:*` matches any `stored-<family>:*`).
|
|
240
|
+
*/
|
|
241
|
+
const RESOURCE_EXPANSIONS = { stored: [
|
|
242
|
+
"stored-agents",
|
|
243
|
+
"stored-mcp-clients",
|
|
244
|
+
"stored-prompt-blocks",
|
|
245
|
+
"stored-scorers",
|
|
246
|
+
"stored-skills",
|
|
247
|
+
"stored-workspaces"
|
|
248
|
+
] };
|
|
249
|
+
/**
|
|
250
|
+
* Check if a permission matches (including wildcard support).
|
|
251
|
+
*
|
|
252
|
+
* Permission format: `{resource}:{action}[:{resource-id}]`
|
|
253
|
+
*
|
|
254
|
+
* Examples:
|
|
255
|
+
* - `*` matches everything
|
|
256
|
+
* - `agents:*` matches `agents:read`, `agents:read:my-agent`
|
|
257
|
+
* - `*:read` matches `agents:read`, `workflows:read` (action across all resources)
|
|
258
|
+
* - `agents:read` matches `agents:read`, `agents:read:my-agent`
|
|
259
|
+
* - `agents:read:my-agent` matches only `agents:read:my-agent`
|
|
260
|
+
* - `agents:*:my-agent` matches `agents:read:my-agent`, `agents:write:my-agent`
|
|
261
|
+
*
|
|
262
|
+
* @param userPermission - Permission the user has
|
|
263
|
+
* @param requiredPermission - Permission being checked
|
|
264
|
+
* @returns True if permission matches
|
|
265
|
+
*/
|
|
266
|
+
function matchesPermission(userPermission, requiredPermission) {
|
|
267
|
+
if (userPermission === "*") return true;
|
|
268
|
+
const grantedParts = userPermission.split(":");
|
|
269
|
+
const requiredParts = requiredPermission.split(":");
|
|
270
|
+
const expandedFamilies = RESOURCE_EXPANSIONS[grantedParts[0] ?? ""];
|
|
271
|
+
if (expandedFamilies && expandedFamilies.includes(requiredParts[0] ?? "")) return matchesPermission([requiredParts[0], ...grantedParts.slice(1)].join(":"), requiredPermission);
|
|
272
|
+
if (grantedParts.length < 2 || requiredParts.length < 2) return userPermission === requiredPermission;
|
|
273
|
+
const [grantedResource, grantedAction, grantedId] = grantedParts;
|
|
274
|
+
const [requiredResource, requiredAction, requiredId] = requiredParts;
|
|
275
|
+
if (grantedResource === "*") {
|
|
276
|
+
if (grantedAction === "*") {
|
|
277
|
+
if (grantedId === void 0) return true;
|
|
278
|
+
return grantedId === requiredId;
|
|
279
|
+
}
|
|
280
|
+
if (grantedAction !== requiredAction) return false;
|
|
281
|
+
if (grantedId === void 0) return true;
|
|
282
|
+
return grantedId === requiredId;
|
|
283
|
+
}
|
|
284
|
+
if (grantedResource !== requiredResource) return false;
|
|
285
|
+
if (grantedAction === "*") {
|
|
286
|
+
if (grantedId === void 0) return true;
|
|
287
|
+
return grantedId === requiredId;
|
|
288
|
+
}
|
|
289
|
+
if (grantedAction !== requiredAction) return false;
|
|
290
|
+
if (grantedId === void 0) return true;
|
|
291
|
+
return grantedId === requiredId;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Resolve permissions from user roles using a role mapping.
|
|
295
|
+
*
|
|
296
|
+
* This function translates provider-defined roles (from WorkOS, Okta, etc.)
|
|
297
|
+
* to Mastra permissions using a configurable mapping.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* const roleMapping = {
|
|
302
|
+
* "Engineering": ["agents:*", "workflows:*"],
|
|
303
|
+
* "Product": ["agents:read"],
|
|
304
|
+
* "_default": [],
|
|
305
|
+
* };
|
|
306
|
+
*
|
|
307
|
+
* // User has "Engineering" and "QA" roles
|
|
308
|
+
* const permissions = resolvePermissionsFromMapping(
|
|
309
|
+
* ["Engineering", "QA"],
|
|
310
|
+
* roleMapping
|
|
311
|
+
* );
|
|
312
|
+
* // Result: ["agents:*", "workflows:*"] (QA is unmapped, gets _default)
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @param roles - User's roles from the identity provider
|
|
316
|
+
* @param mapping - Role to permission mapping
|
|
317
|
+
* @returns Array of resolved permissions
|
|
318
|
+
*/
|
|
319
|
+
function resolvePermissionsFromMapping(roles, mapping) {
|
|
320
|
+
const permissions = /* @__PURE__ */ new Set();
|
|
321
|
+
const defaultPerms = mapping["_default"] ?? [];
|
|
322
|
+
for (const role of roles) {
|
|
323
|
+
const rolePerms = mapping[role];
|
|
324
|
+
if (rolePerms) for (const perm of rolePerms) permissions.add(perm);
|
|
325
|
+
else for (const perm of defaultPerms) permissions.add(perm);
|
|
326
|
+
}
|
|
327
|
+
return Array.from(permissions);
|
|
322
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* @mastra/core/auth/ee
|
|
331
|
+
*
|
|
332
|
+
* Enterprise authentication capabilities for Mastra.
|
|
333
|
+
* This code is licensed under the Mastra Enterprise License - see ee/LICENSE.
|
|
334
|
+
*
|
|
335
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
336
|
+
* @packageDocumentation
|
|
337
|
+
*/
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/index.ts
|
|
323
340
|
const COOKIE_NAME = "wos-session";
|
|
324
341
|
/**
|
|
325
342
|
* Upper bound for shared-API verification fetches. Matches the platform API
|