@mastra/auth-okta 0.1.0 → 0.1.1
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 +12 -0
- package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/base/index.d.ts +31 -0
- package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/logger/index.d.ts +217 -0
- package/dist/_types/@internal_auth/dist/ee/capabilities.d.ts +142 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/index.d.ts +8 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/rbac/index.d.ts +7 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/rbac/static.d.ts +106 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/roles.d.ts +92 -0
- package/dist/_types/@internal_auth/dist/ee/fga-check.d.ts +62 -0
- package/dist/_types/@internal_auth/dist/ee/index.d.ts +15 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/acl.d.ts +140 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/fga.d.ts +350 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/index.d.ts +15 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/permissions.generated.d.ts +519 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/rbac.d.ts +207 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/user.d.ts +18 -0
- package/dist/_types/@internal_auth/dist/ee/license.d.ts +171 -0
- package/dist/_types/@internal_auth/dist/index.d.ts +277 -0
- package/dist/_types/@internal_auth/dist/provider/index.d.ts +125 -0
- package/dist/_types/@internal_auth/dist/session/cookie.d.ts +82 -0
- package/dist/_types/@internal_auth/dist/session/index.d.ts +30 -0
- package/dist/_types/@internal_auth/dist/session/memory.d.ts +60 -0
- package/dist/_types/@internal_auth/dist/types/index.d.ts +52 -0
- package/dist/auth-provider.d.ts +2 -2
- package/dist/auth-provider.d.ts.map +1 -1
- package/dist/index.cjs +297 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +292 -6
- package/dist/index.js.map +1 -1
- package/dist/rbac-provider.d.ts +1 -1
- package/dist/rbac-provider.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/LICENSE.md +0 -30
package/dist/index.js
CHANGED
|
@@ -1,10 +1,83 @@
|
|
|
1
|
-
import { resolvePermissionsFromMapping, matchesPermission } from '@mastra/core/auth/ee';
|
|
2
1
|
import pkg from '@okta/okta-sdk-nodejs';
|
|
3
2
|
import { LRUCache } from 'lru-cache';
|
|
4
|
-
import { MastraAuthProvider } from '@mastra/core/server';
|
|
5
3
|
import { createRemoteJWKSet, jwtVerify } from 'jose';
|
|
6
4
|
|
|
7
|
-
//
|
|
5
|
+
// ../../packages/_internals/auth/dist/chunk-7SVOHBXQ.js
|
|
6
|
+
var RESOURCE_EXPANSIONS = {
|
|
7
|
+
stored: [
|
|
8
|
+
"stored-agents",
|
|
9
|
+
"stored-mcp-clients",
|
|
10
|
+
"stored-prompt-blocks",
|
|
11
|
+
"stored-scorers",
|
|
12
|
+
"stored-skills",
|
|
13
|
+
"stored-workspaces"
|
|
14
|
+
]
|
|
15
|
+
};
|
|
16
|
+
function matchesPermission(userPermission, requiredPermission) {
|
|
17
|
+
if (userPermission === "*") {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
const grantedParts = userPermission.split(":");
|
|
21
|
+
const requiredParts = requiredPermission.split(":");
|
|
22
|
+
const expandedFamilies = RESOURCE_EXPANSIONS[grantedParts[0] ?? ""];
|
|
23
|
+
if (expandedFamilies && expandedFamilies.includes(requiredParts[0] ?? "")) {
|
|
24
|
+
const aliased = [requiredParts[0], ...grantedParts.slice(1)].join(":");
|
|
25
|
+
return matchesPermission(aliased, requiredPermission);
|
|
26
|
+
}
|
|
27
|
+
if (grantedParts.length < 2 || requiredParts.length < 2) {
|
|
28
|
+
return userPermission === requiredPermission;
|
|
29
|
+
}
|
|
30
|
+
const [grantedResource, grantedAction, grantedId] = grantedParts;
|
|
31
|
+
const [requiredResource, requiredAction, requiredId] = requiredParts;
|
|
32
|
+
if (grantedResource === "*") {
|
|
33
|
+
if (grantedAction === "*") {
|
|
34
|
+
if (grantedId === void 0) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return grantedId === requiredId;
|
|
38
|
+
}
|
|
39
|
+
if (grantedAction !== requiredAction) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (grantedId === void 0) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return grantedId === requiredId;
|
|
46
|
+
}
|
|
47
|
+
if (grantedResource !== requiredResource) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (grantedAction === "*") {
|
|
51
|
+
if (grantedId === void 0) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return grantedId === requiredId;
|
|
55
|
+
}
|
|
56
|
+
if (grantedAction !== requiredAction) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (grantedId === void 0) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return grantedId === requiredId;
|
|
63
|
+
}
|
|
64
|
+
function resolvePermissionsFromMapping(roles, mapping) {
|
|
65
|
+
const permissions = /* @__PURE__ */ new Set();
|
|
66
|
+
const defaultPerms = mapping["_default"] ?? [];
|
|
67
|
+
for (const role of roles) {
|
|
68
|
+
const rolePerms = mapping[role];
|
|
69
|
+
if (rolePerms) {
|
|
70
|
+
for (const perm of rolePerms) {
|
|
71
|
+
permissions.add(perm);
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
for (const perm of defaultPerms) {
|
|
75
|
+
permissions.add(perm);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return Array.from(permissions);
|
|
80
|
+
}
|
|
8
81
|
var { Client } = pkg;
|
|
9
82
|
var DEFAULT_CACHE_TTL_MS = 60 * 1e3;
|
|
10
83
|
var DEFAULT_CACHE_MAX_SIZE = 1e3;
|
|
@@ -162,6 +235,187 @@ var MastraRBACOkta = class {
|
|
|
162
235
|
}
|
|
163
236
|
};
|
|
164
237
|
|
|
238
|
+
// ../../packages/_internal-core/dist/chunk-3M4SEWMI.js
|
|
239
|
+
var RegisteredLogger = {
|
|
240
|
+
LLM: "LLM"};
|
|
241
|
+
var LogLevel = {
|
|
242
|
+
DEBUG: "debug",
|
|
243
|
+
INFO: "info",
|
|
244
|
+
WARN: "warn",
|
|
245
|
+
ERROR: "error"};
|
|
246
|
+
var MastraLogger = class {
|
|
247
|
+
name;
|
|
248
|
+
level;
|
|
249
|
+
transports;
|
|
250
|
+
constructor(options = {}) {
|
|
251
|
+
this.name = options.name || "Mastra";
|
|
252
|
+
this.level = options.level || LogLevel.ERROR;
|
|
253
|
+
this.transports = new Map(Object.entries(options.transports || {}));
|
|
254
|
+
}
|
|
255
|
+
getTransports() {
|
|
256
|
+
return this.transports;
|
|
257
|
+
}
|
|
258
|
+
trackException(_error, _metadata) {
|
|
259
|
+
}
|
|
260
|
+
async listLogs(transportId, params) {
|
|
261
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
262
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
263
|
+
}
|
|
264
|
+
return this.transports.get(transportId).listLogs?.(params) ?? {
|
|
265
|
+
logs: [],
|
|
266
|
+
total: 0,
|
|
267
|
+
page: params?.page ?? 1,
|
|
268
|
+
perPage: params?.perPage ?? 100,
|
|
269
|
+
hasMore: false
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
async listLogsByRunId({
|
|
273
|
+
transportId,
|
|
274
|
+
runId,
|
|
275
|
+
fromDate,
|
|
276
|
+
toDate,
|
|
277
|
+
logLevel,
|
|
278
|
+
filters,
|
|
279
|
+
page,
|
|
280
|
+
perPage
|
|
281
|
+
}) {
|
|
282
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
283
|
+
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
284
|
+
}
|
|
285
|
+
return this.transports.get(transportId).listLogsByRunId?.({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
286
|
+
logs: [],
|
|
287
|
+
total: 0,
|
|
288
|
+
page: page ?? 1,
|
|
289
|
+
perPage: perPage ?? 100,
|
|
290
|
+
hasMore: false
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
var ConsoleLogger = class _ConsoleLogger extends MastraLogger {
|
|
295
|
+
component;
|
|
296
|
+
filter;
|
|
297
|
+
constructor(options = {}) {
|
|
298
|
+
super(options);
|
|
299
|
+
this.component = options.component;
|
|
300
|
+
this.filter = options.filter;
|
|
301
|
+
}
|
|
302
|
+
child(componentOrBindings) {
|
|
303
|
+
const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
|
|
304
|
+
return new _ConsoleLogger({
|
|
305
|
+
name: this.name,
|
|
306
|
+
level: this.level,
|
|
307
|
+
component,
|
|
308
|
+
filter: this.filter
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
shouldLog(level, message, args) {
|
|
312
|
+
if (!this.filter) return true;
|
|
313
|
+
try {
|
|
314
|
+
return this.filter({ component: this.component, level, message, args });
|
|
315
|
+
} catch (e) {
|
|
316
|
+
console.error(`[Logger] Filter error for component=${this.component} level=${level}:`, e);
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
prefix() {
|
|
321
|
+
return this.component ? `[${this.component}] ` : "";
|
|
322
|
+
}
|
|
323
|
+
debug(message, ...args) {
|
|
324
|
+
if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) {
|
|
325
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
info(message, ...args) {
|
|
329
|
+
if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) {
|
|
330
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
warn(message, ...args) {
|
|
334
|
+
if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) {
|
|
335
|
+
console.warn(`${this.prefix()}${message}`, ...args);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
error(message, ...args) {
|
|
339
|
+
if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) {
|
|
340
|
+
console.error(`${this.prefix()}${message}`, ...args);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
async listLogs(_transportId, _params) {
|
|
344
|
+
return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };
|
|
345
|
+
}
|
|
346
|
+
async listLogsByRunId(_args) {
|
|
347
|
+
return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// ../../packages/_internal-core/dist/base/index.js
|
|
352
|
+
var MastraBase = class {
|
|
353
|
+
component = RegisteredLogger.LLM;
|
|
354
|
+
logger;
|
|
355
|
+
name;
|
|
356
|
+
#rawConfig;
|
|
357
|
+
constructor({
|
|
358
|
+
component,
|
|
359
|
+
name,
|
|
360
|
+
rawConfig
|
|
361
|
+
}) {
|
|
362
|
+
this.component = component || RegisteredLogger.LLM;
|
|
363
|
+
this.name = name;
|
|
364
|
+
this.#rawConfig = rawConfig;
|
|
365
|
+
this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Returns the raw storage configuration this primitive was created from,
|
|
369
|
+
* or undefined if it was created from code.
|
|
370
|
+
*/
|
|
371
|
+
toRawConfig() {
|
|
372
|
+
return this.#rawConfig;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Sets the raw storage configuration for this primitive.
|
|
376
|
+
* @internal
|
|
377
|
+
*/
|
|
378
|
+
__setRawConfig(rawConfig) {
|
|
379
|
+
this.#rawConfig = rawConfig;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Set the logger for the agent
|
|
383
|
+
* @param logger
|
|
384
|
+
*/
|
|
385
|
+
__setLogger(logger) {
|
|
386
|
+
this.logger = "child" in logger && typeof logger.child === "function" ? logger.child({ component: this.component }) : logger;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// ../../packages/_internals/auth/dist/chunk-XG6GH2VJ.js
|
|
391
|
+
var MastraAuthProvider = class extends MastraBase {
|
|
392
|
+
protected;
|
|
393
|
+
public;
|
|
394
|
+
constructor(options) {
|
|
395
|
+
super({ component: "AUTH", name: options?.name });
|
|
396
|
+
if (options?.authorizeUser) {
|
|
397
|
+
this.authorizeUser = options.authorizeUser.bind(this);
|
|
398
|
+
}
|
|
399
|
+
this.protected = options?.protected;
|
|
400
|
+
this.public = options?.public;
|
|
401
|
+
this.mapUserToResourceId = options?.mapUserToResourceId;
|
|
402
|
+
}
|
|
403
|
+
registerOptions(opts) {
|
|
404
|
+
if (opts?.authorizeUser) {
|
|
405
|
+
this.authorizeUser = opts.authorizeUser.bind(this);
|
|
406
|
+
}
|
|
407
|
+
if (opts?.mapUserToResourceId) {
|
|
408
|
+
this.mapUserToResourceId = opts.mapUserToResourceId;
|
|
409
|
+
}
|
|
410
|
+
if (opts?.protected) {
|
|
411
|
+
this.protected = opts.protected;
|
|
412
|
+
}
|
|
413
|
+
if (opts?.public) {
|
|
414
|
+
this.public = opts.public;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
165
419
|
// src/types.ts
|
|
166
420
|
function mapOktaClaimsToUser(payload) {
|
|
167
421
|
return {
|
|
@@ -180,7 +434,7 @@ function mapOktaClaimsToUser(payload) {
|
|
|
180
434
|
}
|
|
181
435
|
|
|
182
436
|
// src/auth-provider.ts
|
|
183
|
-
function
|
|
437
|
+
function getRequestHeader2(request, name) {
|
|
184
438
|
if (request instanceof Request) {
|
|
185
439
|
return request.headers.get(name);
|
|
186
440
|
}
|
|
@@ -372,7 +626,7 @@ var MastraAuthOkta = class extends MastraAuthProvider {
|
|
|
372
626
|
*/
|
|
373
627
|
async getUserFromSession(request) {
|
|
374
628
|
try {
|
|
375
|
-
const cookieHeader =
|
|
629
|
+
const cookieHeader = getRequestHeader2(request, "cookie");
|
|
376
630
|
if (!cookieHeader) return null;
|
|
377
631
|
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
378
632
|
const sessionCookie = cookies.find((c) => c.startsWith(`${this.cookieName}=`));
|
|
@@ -394,7 +648,7 @@ var MastraAuthOkta = class extends MastraAuthProvider {
|
|
|
394
648
|
*/
|
|
395
649
|
async getIdTokenFromSession(request) {
|
|
396
650
|
try {
|
|
397
|
-
const cookieHeader =
|
|
651
|
+
const cookieHeader = getRequestHeader2(request, "cookie");
|
|
398
652
|
if (!cookieHeader) return null;
|
|
399
653
|
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
400
654
|
const sessionCookie = cookies.find((c) => c.startsWith(`${this.cookieName}=`));
|
|
@@ -587,6 +841,38 @@ var MastraAuthOkta = class extends MastraAuthProvider {
|
|
|
587
841
|
return this.issuer;
|
|
588
842
|
}
|
|
589
843
|
};
|
|
844
|
+
/**
|
|
845
|
+
* EE Authentication Interfaces
|
|
846
|
+
*
|
|
847
|
+
* Enterprise interfaces for RBAC, ACL, and advanced authorization.
|
|
848
|
+
*
|
|
849
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
850
|
+
* @packageDocumentation
|
|
851
|
+
*/
|
|
852
|
+
/**
|
|
853
|
+
* FGA enforcement utility for checking fine-grained authorization.
|
|
854
|
+
*
|
|
855
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
856
|
+
*/
|
|
857
|
+
/**
|
|
858
|
+
* RBAC provider implementations.
|
|
859
|
+
*
|
|
860
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
861
|
+
*/
|
|
862
|
+
/**
|
|
863
|
+
* Default implementations for EE authentication.
|
|
864
|
+
*
|
|
865
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
866
|
+
*/
|
|
867
|
+
/**
|
|
868
|
+
* @mastra/core/auth/ee
|
|
869
|
+
*
|
|
870
|
+
* Enterprise authentication capabilities for Mastra.
|
|
871
|
+
* This code is licensed under the Mastra Enterprise License - see ee/LICENSE.
|
|
872
|
+
*
|
|
873
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
874
|
+
* @packageDocumentation
|
|
875
|
+
*/
|
|
590
876
|
|
|
591
877
|
export { MastraAuthOkta, MastraRBACOkta, mapOktaClaimsToUser };
|
|
592
878
|
//# sourceMappingURL=index.js.map
|