@mastra/auth-okta 0.1.2 → 0.2.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 CHANGED
@@ -1,5 +1,63 @@
1
1
  # @mastra/auth-okta
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added an `audience` option to `MastraAuthOkta` so bearer-token verification is no longer pinned to the OAuth client ID. ([#21117](https://github.com/mastra-ai/mastra/pull/21117))
8
+
9
+ Previously the provider always required `aud` to equal the client ID, which is the audience of an Okta **ID token**. Okta **access tokens** carry the authorization server's audience instead, so machine-to-machine callers (MCP clients, CI jobs, service-to-service traffic) always got a 401 on an org authorization server. Those callers have no session cookie, so bearer was their only way in.
10
+
11
+ Set `audience` (or the `OKTA_AUDIENCE` environment variable) to the audience your tokens actually carry:
12
+
13
+ ```typescript
14
+ // Before: only ID tokens whose aud is the client ID were accepted
15
+ const auth = new MastraAuthOkta({ domain, clientId, clientSecret, redirectUri });
16
+
17
+ // After: accept access tokens from an org authorization server
18
+ const auth = new MastraAuthOkta({
19
+ domain,
20
+ clientId,
21
+ clientSecret,
22
+ redirectUri,
23
+ audience: 'https://your-org.okta.com',
24
+ });
25
+
26
+ // Or accept both ID tokens from the browser and access tokens from services
27
+ const auth = new MastraAuthOkta({ /* ... */ audience: [clientId, 'api://default'] });
28
+ ```
29
+
30
+ The default is unchanged, so existing setups keep working.
31
+
32
+ ## 0.2.0-alpha.0
33
+
34
+ ### Minor Changes
35
+
36
+ - Added an `audience` option to `MastraAuthOkta` so bearer-token verification is no longer pinned to the OAuth client ID. ([#21117](https://github.com/mastra-ai/mastra/pull/21117))
37
+
38
+ Previously the provider always required `aud` to equal the client ID, which is the audience of an Okta **ID token**. Okta **access tokens** carry the authorization server's audience instead, so machine-to-machine callers (MCP clients, CI jobs, service-to-service traffic) always got a 401 on an org authorization server. Those callers have no session cookie, so bearer was their only way in.
39
+
40
+ Set `audience` (or the `OKTA_AUDIENCE` environment variable) to the audience your tokens actually carry:
41
+
42
+ ```typescript
43
+ // Before: only ID tokens whose aud is the client ID were accepted
44
+ const auth = new MastraAuthOkta({ domain, clientId, clientSecret, redirectUri });
45
+
46
+ // After: accept access tokens from an org authorization server
47
+ const auth = new MastraAuthOkta({
48
+ domain,
49
+ clientId,
50
+ clientSecret,
51
+ redirectUri,
52
+ audience: 'https://your-org.okta.com',
53
+ });
54
+
55
+ // Or accept both ID tokens from the browser and access tokens from services
56
+ const auth = new MastraAuthOkta({ /* ... */ audience: [clientId, 'api://default'] });
57
+ ```
58
+
59
+ The default is unchanged, so existing setups keep working.
60
+
3
61
  ## 0.1.2
4
62
 
5
63
  ### Patch Changes
package/README.md CHANGED
@@ -81,6 +81,7 @@ const mastra = new Mastra({
81
81
  | `OKTA_CLIENT_SECRET` | OAuth client secret | For auth only |
82
82
  | `OKTA_REDIRECT_URI` | OAuth redirect URI for SSO callback | For auth only |
83
83
  | `OKTA_ISSUER` | Token issuer URL | No (defaults to `https://{domain}/oauth2/default`) |
84
+ | `OKTA_AUDIENCE` | Expected `aud` claim on bearer tokens | No (defaults to `OKTA_CLIENT_ID`) |
84
85
  | `OKTA_COOKIE_PASSWORD` | Session encryption key (min 32 chars) | No (auto-generated if omitted; set for production) |
85
86
  | `OKTA_API_TOKEN` | API token for management SDK | For RBAC only |
86
87
 
@@ -93,6 +94,7 @@ interface MastraAuthOktaOptions {
93
94
  clientSecret?: string; // OAuth client secret (or OKTA_CLIENT_SECRET)
94
95
  redirectUri?: string; // SSO callback URI (or OKTA_REDIRECT_URI)
95
96
  issuer?: string; // Token issuer URL (or OKTA_ISSUER)
97
+ audience?: string | string[]; // Expected bearer-token `aud` (or OKTA_AUDIENCE; defaults to clientId)
96
98
  scopes?: string[]; // OAuth scopes (default: ['openid', 'profile', 'email', 'groups'])
97
99
  name?: string; // Provider name (default: 'okta')
98
100
  session?: {
@@ -1,31 +1,31 @@
1
- import { RegisteredLogger, IMastraLogger } from '../logger/index.js';
2
- import 'node:stream';
3
-
1
+ import { i as IMastraLogger, u as RegisteredLogger } from "../index-S1lgaKO7.js";
2
+ //#region src/base/MastraBase.d.ts
4
3
  declare class MastraBase {
5
- #private;
6
- component: RegisteredLogger;
7
- protected logger: IMastraLogger;
4
+ #private;
5
+ component: RegisteredLogger;
6
+ protected logger: IMastraLogger;
7
+ name?: string;
8
+ constructor({ component, name, rawConfig }: {
9
+ component?: RegisteredLogger;
8
10
  name?: string;
9
- constructor({ component, name, rawConfig, }: {
10
- component?: RegisteredLogger;
11
- name?: string;
12
- rawConfig?: Record<string, unknown>;
13
- });
14
- /**
15
- * Returns the raw storage configuration this primitive was created from,
16
- * or undefined if it was created from code.
17
- */
18
- toRawConfig(): Record<string, unknown> | undefined;
19
- /**
20
- * Sets the raw storage configuration for this primitive.
21
- * @internal
22
- */
23
- __setRawConfig(rawConfig: Record<string, unknown>): void;
24
- /**
25
- * Set the logger for the agent
26
- * @param logger
27
- */
28
- __setLogger(logger: IMastraLogger): void;
11
+ rawConfig?: Record<string, unknown>;
12
+ });
13
+ /**
14
+ * Returns the raw storage configuration this primitive was created from,
15
+ * or undefined if it was created from code.
16
+ */
17
+ toRawConfig(): Record<string, unknown> | undefined;
18
+ /**
19
+ * Sets the raw storage configuration for this primitive.
20
+ * @internal
21
+ */
22
+ __setRawConfig(rawConfig: Record<string, unknown>): void;
23
+ /**
24
+ * Set the logger for the agent
25
+ * @param logger
26
+ */
27
+ __setLogger(logger: IMastraLogger): void;
29
28
  }
30
-
29
+ //#endregion
31
30
  export { MastraBase };
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,218 @@
1
+ import { Transform } from "stream";
2
+ //#region src/logger/index.d.ts
3
+ declare const RegisteredLogger: {
4
+ readonly AGENT: "AGENT";
5
+ readonly OBSERVABILITY: "OBSERVABILITY";
6
+ readonly AUTH: "AUTH";
7
+ readonly BROWSER: "BROWSER";
8
+ readonly NETWORK: "NETWORK";
9
+ readonly WORKFLOW: "WORKFLOW";
10
+ readonly LLM: "LLM";
11
+ readonly TTS: "TTS";
12
+ readonly VOICE: "VOICE";
13
+ readonly VECTOR: "VECTOR";
14
+ readonly BUNDLER: "BUNDLER";
15
+ readonly DEPLOYER: "DEPLOYER";
16
+ readonly MEMORY: "MEMORY";
17
+ readonly STORAGE: "STORAGE";
18
+ readonly EMBEDDINGS: "EMBEDDINGS";
19
+ readonly MCP_SERVER: "MCP_SERVER";
20
+ readonly SERVER_CACHE: "SERVER_CACHE";
21
+ readonly SERVER: "SERVER";
22
+ readonly WORKSPACE: "WORKSPACE";
23
+ readonly CHANNEL: "CHANNEL";
24
+ };
25
+ type RegisteredLogger = (typeof RegisteredLogger)[keyof typeof RegisteredLogger];
26
+ declare const LogLevel: {
27
+ readonly DEBUG: "debug";
28
+ readonly INFO: "info";
29
+ readonly WARN: "warn";
30
+ readonly ERROR: "error";
31
+ readonly NONE: "silent";
32
+ };
33
+ type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
34
+ interface BaseLogMessage {
35
+ runId?: string;
36
+ msg: string;
37
+ level: LogLevel;
38
+ time: Date;
39
+ pid: number;
40
+ hostname: string;
41
+ name: string;
42
+ }
43
+ declare abstract class LoggerTransport extends Transform {
44
+ constructor(opts?: any);
45
+ listLogsByRunId(_args: {
46
+ runId: string;
47
+ fromDate?: Date;
48
+ toDate?: Date;
49
+ logLevel?: LogLevel;
50
+ filters?: Record<string, any>;
51
+ page?: number;
52
+ perPage?: number;
53
+ }): Promise<{
54
+ logs: BaseLogMessage[];
55
+ total: number;
56
+ page: number;
57
+ perPage: number;
58
+ hasMore: boolean;
59
+ }>;
60
+ listLogs(_args?: {
61
+ fromDate?: Date;
62
+ toDate?: Date;
63
+ logLevel?: LogLevel;
64
+ filters?: Record<string, any>;
65
+ returnPaginationResults?: boolean;
66
+ page?: number;
67
+ perPage?: number;
68
+ }): Promise<{
69
+ logs: BaseLogMessage[];
70
+ total: number;
71
+ page: number;
72
+ perPage: number;
73
+ hasMore: boolean;
74
+ }>;
75
+ }
76
+ declare const createCustomTransport: (stream: Transform, listLogs?: LoggerTransport["listLogs"], listLogsByRunId?: LoggerTransport["listLogsByRunId"]) => LoggerTransport;
77
+ interface IMastraLogger {
78
+ debug(message: string, ...args: any[]): void;
79
+ info(message: string, ...args: any[]): void;
80
+ warn(message: string, ...args: any[]): void;
81
+ error(message: string, ...args: any[]): void;
82
+ trackException(error: Error, metadata?: Record<string, unknown>): void;
83
+ getTransports(): Map<string, LoggerTransport>;
84
+ listLogs(_transportId: string, _params?: {
85
+ fromDate?: Date;
86
+ toDate?: Date;
87
+ logLevel?: LogLevel;
88
+ filters?: Record<string, any>;
89
+ page?: number;
90
+ perPage?: number;
91
+ }): Promise<{
92
+ logs: BaseLogMessage[];
93
+ total: number;
94
+ page: number;
95
+ perPage: number;
96
+ hasMore: boolean;
97
+ }>;
98
+ listLogsByRunId(_args: {
99
+ transportId: string;
100
+ runId: string;
101
+ fromDate?: Date;
102
+ toDate?: Date;
103
+ logLevel?: LogLevel;
104
+ filters?: Record<string, any>;
105
+ page?: number;
106
+ perPage?: number;
107
+ }): Promise<{
108
+ logs: BaseLogMessage[];
109
+ total: number;
110
+ page: number;
111
+ perPage: number;
112
+ hasMore: boolean;
113
+ }>;
114
+ }
115
+ declare abstract class MastraLogger implements IMastraLogger {
116
+ protected name: string;
117
+ protected level: LogLevel;
118
+ protected transports: Map<string, LoggerTransport>;
119
+ constructor(options?: {
120
+ name?: string;
121
+ level?: LogLevel;
122
+ transports?: Record<string, LoggerTransport>;
123
+ });
124
+ abstract debug(message: string, ...args: any[]): void;
125
+ abstract info(message: string, ...args: any[]): void;
126
+ abstract warn(message: string, ...args: any[]): void;
127
+ abstract error(message: string, ...args: any[]): void;
128
+ getTransports(): Map<string, LoggerTransport>;
129
+ trackException(_error: Error, _metadata?: Record<string, unknown>): void;
130
+ listLogs(transportId: string, params?: {
131
+ fromDate?: Date;
132
+ toDate?: Date;
133
+ logLevel?: LogLevel;
134
+ filters?: Record<string, any>;
135
+ page?: number;
136
+ perPage?: number;
137
+ }): Promise<{
138
+ logs: BaseLogMessage[];
139
+ total: number;
140
+ page: number;
141
+ perPage: number;
142
+ hasMore: boolean;
143
+ }>;
144
+ listLogsByRunId({ transportId, runId, fromDate, toDate, logLevel, filters, page, perPage }: {
145
+ transportId: string;
146
+ runId: string;
147
+ fromDate?: Date;
148
+ toDate?: Date;
149
+ logLevel?: LogLevel;
150
+ filters?: Record<string, any>;
151
+ page?: number;
152
+ perPage?: number;
153
+ }): Promise<{
154
+ logs: BaseLogMessage[];
155
+ total: number;
156
+ page: number;
157
+ perPage: number;
158
+ hasMore: boolean;
159
+ }>;
160
+ }
161
+ type LogFilterContext = {
162
+ component?: RegisteredLogger;
163
+ level: LogLevel;
164
+ message: string;
165
+ args: unknown[];
166
+ };
167
+ type LogFilter = (ctx: LogFilterContext) => boolean;
168
+ interface ConsoleLoggerOptions {
169
+ name?: string;
170
+ level?: LogLevel;
171
+ component?: RegisteredLogger;
172
+ filter?: LogFilter;
173
+ }
174
+ declare class ConsoleLogger extends MastraLogger {
175
+ protected component?: RegisteredLogger;
176
+ protected filter?: LogFilter;
177
+ constructor(options?: ConsoleLoggerOptions);
178
+ child(componentOrBindings: RegisteredLogger | Record<string, unknown>): ConsoleLogger;
179
+ private shouldLog;
180
+ private prefix;
181
+ debug(message: string, ...args: any[]): void;
182
+ info(message: string, ...args: any[]): void;
183
+ warn(message: string, ...args: any[]): void;
184
+ error(message: string, ...args: any[]): void;
185
+ listLogs(_transportId: string, _params?: {
186
+ fromDate?: Date;
187
+ toDate?: Date;
188
+ logLevel?: LogLevel;
189
+ filters?: Record<string, any>;
190
+ page?: number;
191
+ perPage?: number;
192
+ }): Promise<{
193
+ logs: never[];
194
+ total: number;
195
+ page: number;
196
+ perPage: number;
197
+ hasMore: boolean;
198
+ }>;
199
+ listLogsByRunId(_args: {
200
+ transportId: string;
201
+ runId: string;
202
+ fromDate?: Date;
203
+ toDate?: Date;
204
+ logLevel?: LogLevel;
205
+ filters?: Record<string, any>;
206
+ page?: number;
207
+ perPage?: number;
208
+ }): Promise<{
209
+ logs: never[];
210
+ total: number;
211
+ page: number;
212
+ perPage: number;
213
+ hasMore: boolean;
214
+ }>;
215
+ }
216
+ //#endregion
217
+ export { LogFilter as a, LoggerTransport as c, createCustomTransport as d, IMastraLogger as i, MastraLogger as l, ConsoleLogger as n, LogFilterContext as o, ConsoleLoggerOptions as r, LogLevel as s, BaseLogMessage as t, RegisteredLogger as u };
218
+ //# sourceMappingURL=index-S1lgaKO7.d.ts.map
@@ -3,12 +3,9 @@
3
3
  *
4
4
  * @license Mastra Enterprise License - see ee/LICENSE
5
5
  */
6
- import type { FGACheckContext, IFGAProvider } from './interfaces/fga.js';
6
+ import type { ActorSignal, FGACheckContext, IFGAProvider } from './interfaces/fga.js';
7
7
  import type { MastraFGAPermissionInput } from './interfaces/permissions.generated.js';
8
- export type ActorSignal = true | {
9
- actorKind: 'system';
10
- sourceWorkflow?: string;
11
- };
8
+ export type { ActorSignal };
12
9
  export interface CheckFGAOptions {
13
10
  fgaProvider: IFGAProvider | undefined;
14
11
  user: any;
@@ -8,6 +8,34 @@
8
8
  * @license Mastra Enterprise License - see ee/LICENSE
9
9
  */
10
10
  import type { MastraFGAPermissionInput } from './permissions.generated.js';
11
+ /**
12
+ * Signals that a call is made by a trusted non-user actor rather than an
13
+ * authenticated end user.
14
+ *
15
+ * - `true` is the anonymous system shorthand.
16
+ * - The object form additionally names the acting agent (`agentId`) and carries
17
+ * the permission grants / scope a provider can enforce for least privilege.
18
+ */
19
+ export type ActorSignal = true | {
20
+ actorKind: 'system';
21
+ sourceWorkflow?: string;
22
+ /**
23
+ * Identity of the acting system agent. Unlike the check `resource` (the
24
+ * target), this names the actor itself so a provider can enforce
25
+ * per-agent least privilege.
26
+ */
27
+ agentId?: string;
28
+ /**
29
+ * Permission grants *claimed* for this actor — the actor analog of a
30
+ * user's resolved permissions. This is an untrusted, self-asserted hint:
31
+ * a provider enforcing real least privilege should resolve the actor's
32
+ * authoritative grants from a trusted source (e.g. a manifest or FGA,
33
+ * keyed by `agentId`) rather than trusting these values directly.
34
+ */
35
+ permissions?: MastraFGAPermissionInput[];
36
+ /** Additional provider-specific scope for the actor (e.g. tenant, environment). */
37
+ scope?: Record<string, string>;
38
+ };
11
39
  /**
12
40
  * Optional context for an authorization check.
13
41
  */
@@ -306,6 +334,25 @@ export interface IFGAProvider<TUser = unknown> {
306
334
  filterAccessible<T extends {
307
335
  id: string;
308
336
  }>(user: TUser, resources: T[], resourceType: string, permission: MastraFGAPermissionInput): Promise<T[]>;
337
+ /**
338
+ * Authorize a non-user (system / autonomous agent) actor.
339
+ *
340
+ * System actors bypass the user-centric `require()` path. Implement this
341
+ * method to opt in to provider-driven least privilege for those actors:
342
+ * decide whether the actor (identified by `actor.agentId` and constrained by
343
+ * `actor.permissions` / `actor.scope`) may perform `permission` on
344
+ * `resource`, and throw {@link FGADeniedError} to deny.
345
+ *
346
+ * When this method is not implemented, Mastra preserves the legacy
347
+ * trusted-actor bypass (allow after the tenant-scope check). Adding it is
348
+ * therefore fully backward compatible.
349
+ *
350
+ * @param actor - The system actor signal (`true` shorthand, or an object with
351
+ * `agentId`, `permissions`, `scope`).
352
+ * @param params - The resource and permission being attempted.
353
+ * @throws FGADeniedError if the actor may not perform the action.
354
+ */
355
+ requireActor?(actor: ActorSignal, params: FGACheckParams): Promise<void>;
309
356
  }
310
357
  /**
311
358
  * Extended FGA interface with write operations for managing resources and role assignments.
@@ -10,7 +10,7 @@
10
10
  * All known API resources.
11
11
  * Derived from SERVER_ROUTES paths in @mastra/server.
12
12
  */
13
- export declare const RESOURCES: readonly ["a2a", "agent-builder", "agent-controller", "agents", "auth", "background-tasks", "channels", "datasets", "embedders", "experiments", "infrastructure", "logs", "mcp", "memory", "observability", "processor-providers", "processors", "schedules", "scores", "stored-agents", "stored-mcp-clients", "stored-prompt-blocks", "stored-scorers", "stored-skills", "stored-workspaces", "system", "tool-providers", "tools", "vector", "vectors", "workflows", "workspaces"];
13
+ export declare const RESOURCES: readonly ["a2a", "agent-builder", "agent-controller", "agents", "auth", "background-tasks", "channels", "datasets", "embedders", "experiments", "infrastructure", "logs", "mcp", "memory", "observability", "processor-providers", "processors", "schedules", "scores", "stored-agents", "stored-mcp-clients", "stored-prompt-blocks", "stored-scorers", "stored-skills", "stored-workflows", "stored-workspaces", "system", "tool-providers", "tools", "vector", "vectors", "workflows", "workspaces"];
14
14
  /**
15
15
  * Resource type union.
16
16
  */
@@ -98,6 +98,8 @@ export declare const PERMISSION_PATTERNS: {
98
98
  readonly 'stored-scorers:*': "stored-scorers:*";
99
99
  /** Full access to stored skills */
100
100
  readonly 'stored-skills:*': "stored-skills:*";
101
+ /** Full access to stored workflows */
102
+ readonly 'stored-workflows:*': "stored-workflows:*";
101
103
  /** Full access to stored workspaces */
102
104
  readonly 'stored-workspaces:*': "stored-workspaces:*";
103
105
  /** Full access to system info */
@@ -238,6 +240,10 @@ export declare const PERMISSION_PATTERNS: {
238
240
  readonly 'stored-skills:read': "stored-skills:read";
239
241
  /** Create and modify stored skills */
240
242
  readonly 'stored-skills:write': "stored-skills:write";
243
+ /** View stored workflows */
244
+ readonly 'stored-workflows:read': "stored-workflows:read";
245
+ /** Create and modify stored workflows */
246
+ readonly 'stored-workflows:write': "stored-workflows:write";
241
247
  /** Delete stored workspaces */
242
248
  readonly 'stored-workspaces:delete': "stored-workspaces:delete";
243
249
  /** View stored workspaces */
@@ -305,7 +311,7 @@ export type PermissionPattern = keyof typeof PERMISSION_PATTERNS;
305
311
  /**
306
312
  * All valid resource:action permission combinations (excludes wildcards).
307
313
  */
308
- export declare const PERMISSIONS: readonly ["a2a:read", "a2a:write", "agent-builder:execute", "agent-builder:read", "agent-builder:write", "agent-controller:execute", "agent-controller:read", "agents:create", "agents:delete", "agents:execute", "agents:read", "agents:write", "auth:read", "background-tasks:read", "channels:read", "channels:write", "datasets:delete", "datasets:execute", "datasets:read", "datasets:write", "embedders:read", "experiments:read", "infrastructure:read", "logs:read", "mcp:execute", "mcp:read", "mcp:write", "memory:delete", "memory:execute", "memory:read", "memory:write", "observability:read", "observability:write", "processor-providers:read", "processors:execute", "processors:read", "schedules:delete", "schedules:execute", "schedules:read", "schedules:write", "scores:read", "scores:write", "stored-agents:delete", "stored-agents:publish", "stored-agents:read", "stored-agents:write", "stored-mcp-clients:delete", "stored-mcp-clients:publish", "stored-mcp-clients:read", "stored-mcp-clients:write", "stored-prompt-blocks:delete", "stored-prompt-blocks:publish", "stored-prompt-blocks:read", "stored-prompt-blocks:write", "stored-scorers:delete", "stored-scorers:publish", "stored-scorers:read", "stored-scorers:write", "stored-skills:delete", "stored-skills:publish", "stored-skills:read", "stored-skills:write", "stored-workspaces:delete", "stored-workspaces:read", "stored-workspaces:write", "system:read", "tool-providers:delete", "tool-providers:read", "tool-providers:write", "tools:execute", "tools:read", "vector:delete", "vector:execute", "vector:read", "vector:write", "vectors:read", "workflows:delete", "workflows:execute", "workflows:read", "workflows:write", "workspaces:delete", "workspaces:read", "workspaces:write"];
314
+ export declare const PERMISSIONS: readonly ["a2a:read", "a2a:write", "agent-builder:execute", "agent-builder:read", "agent-builder:write", "agent-controller:execute", "agent-controller:read", "agents:create", "agents:delete", "agents:execute", "agents:read", "agents:write", "auth:read", "background-tasks:read", "channels:read", "channels:write", "datasets:delete", "datasets:execute", "datasets:read", "datasets:write", "embedders:read", "experiments:read", "infrastructure:read", "logs:read", "mcp:execute", "mcp:read", "mcp:write", "memory:delete", "memory:execute", "memory:read", "memory:write", "observability:read", "observability:write", "processor-providers:read", "processors:execute", "processors:read", "schedules:delete", "schedules:execute", "schedules:read", "schedules:write", "scores:read", "scores:write", "stored-agents:delete", "stored-agents:publish", "stored-agents:read", "stored-agents:write", "stored-mcp-clients:delete", "stored-mcp-clients:publish", "stored-mcp-clients:read", "stored-mcp-clients:write", "stored-prompt-blocks:delete", "stored-prompt-blocks:publish", "stored-prompt-blocks:read", "stored-prompt-blocks:write", "stored-scorers:delete", "stored-scorers:publish", "stored-scorers:read", "stored-scorers:write", "stored-skills:delete", "stored-skills:publish", "stored-skills:read", "stored-skills:write", "stored-workflows:read", "stored-workflows:write", "stored-workspaces:delete", "stored-workspaces:read", "stored-workspaces:write", "system:read", "tool-providers:delete", "tool-providers:read", "tool-providers:write", "tools:execute", "tools:read", "vector:delete", "vector:execute", "vector:read", "vector:write", "vectors:read", "workflows:delete", "workflows:execute", "workflows:read", "workflows:write", "workspaces:delete", "workspaces:read", "workspaces:write"];
309
315
  /**
310
316
  * Specific permission type (e.g., 'agents:read', 'workflows:execute').
311
317
  */
@@ -441,6 +447,10 @@ export declare const MastraFGAPermissions: {
441
447
  readonly STORED_SKILLS_READ: "stored-skills:read";
442
448
  /** Create and modify stored skills */
443
449
  readonly STORED_SKILLS_WRITE: "stored-skills:write";
450
+ /** View stored workflows */
451
+ readonly STORED_WORKFLOWS_READ: "stored-workflows:read";
452
+ /** Create and modify stored workflows */
453
+ readonly STORED_WORKFLOWS_WRITE: "stored-workflows:write";
444
454
  /** Delete stored workspaces */
445
455
  readonly STORED_WORKSPACES_DELETE: "stored-workspaces:delete";
446
456
  /** View stored workspaces */
@@ -270,6 +270,72 @@ export interface ICredentialsProvider<TUser extends User = User> {
270
270
  */
271
271
  isSignUpEnabled?(): boolean;
272
272
  }
273
+ /**
274
+ * Provider interface for organization membership management.
275
+ *
276
+ * Implement this interface to enable multi-tenant hosts (e.g. the Mastra Code
277
+ * web factory) to bootstrap a personal organization for new users and to
278
+ * authorize organization-level administrative mutations.
279
+ */
280
+ export interface IOrganizationsProvider {
281
+ /**
282
+ * Ensure the user belongs to an organization, bootstrapping a personal org
283
+ * on first use when they have none. Must be idempotent under
284
+ * concurrent/retried first logins.
285
+ *
286
+ * @param userId - Stable provider user id
287
+ * @returns The organization id, or `undefined` when the user genuinely
288
+ * stays no-org (bootstrap is best-effort)
289
+ */
290
+ ensureOrganization(userId: string): Promise<string | undefined>;
291
+ /**
292
+ * Whether the user holds an admin-equivalent role in the organization.
293
+ * Provider errors should resolve to `false` rather than throw.
294
+ *
295
+ * @param organizationId - Organization id
296
+ * @param userId - Stable provider user id
297
+ */
298
+ isOrganizationAdmin(organizationId: string, userId: string): Promise<boolean>;
299
+ }
300
+ /**
301
+ * Host-level context handed to {@link IAuthInit.init} once during server
302
+ * preparation. Storage-agnostic: hosts pass whatever database handle their
303
+ * storage backend exposes.
304
+ */
305
+ export interface AuthInitContext {
306
+ /**
307
+ * Database handle for providers that persist their own auth tables
308
+ * (e.g. better-auth). Shape is provider-defined; hosts pass their storage
309
+ * backend's auth database as-is.
310
+ */
311
+ database?: unknown;
312
+ /** Browser-facing origin (no trailing slash), e.g. `https://factory.acme.com`. */
313
+ publicUrl?: string;
314
+ /**
315
+ * Extra browser origins allowed to talk to the API (cross-origin SPA
316
+ * deploys). Providers that enforce their own origin allow-list (e.g.
317
+ * better-auth `trustedOrigins`) must honor these.
318
+ */
319
+ allowedOrigins?: string[];
320
+ }
321
+ /**
322
+ * Optional one-time initialization hook for auth providers. Hosts call
323
+ * `init()` once during preparation with host-level context (database, public
324
+ * origin) so providers can consume it without the deploy entry passing it
325
+ * twice. Providers should fail fast here for requirements only satisfiable at
326
+ * prepare time.
327
+ */
328
+ export interface IAuthInit {
329
+ init(ctx: AuthInitContext): Promise<void>;
330
+ }
331
+ /**
332
+ * Provider interface for handling raw auth HTTP requests. Providers that ship
333
+ * their own HTTP API surface (e.g. better-auth's `/api/auth/*` handler)
334
+ * implement this so hosts can mount it (typically under `/auth/api/*`).
335
+ */
336
+ export interface IAuthHttpHandler {
337
+ handleAuthRequest(request: Request): Promise<Response>;
338
+ }
273
339
  export * from './session/index.js';
274
340
  export * from './provider/index.js';
275
341
  export * from './types/index.js';
@@ -1,5 +1,5 @@
1
1
  import { MastraBase } from '../_types/@internal_core/dist/base/index.d.ts';
2
- import type { CredentialsResult, ISSOProvider, ISessionProvider, IUserProvider, Session, SSOCallbackResult, SSOLoginConfig, User } from '..';
2
+ import type { CredentialsResult, IAuthHttpHandler, IAuthInit, ICredentialsProvider, IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, Session, SSOCallbackResult, SSOLoginConfig, User } from '..';
3
3
  import type { AuthorizeUserFn, MastraAuthConfig, MastraAuthRequest } from '../types/index.js';
4
4
  export interface MastraAuthProviderOptions<TUser = unknown> {
5
5
  name?: string;
@@ -72,6 +72,13 @@ export declare abstract class MastraAuthProvider<TUser = unknown> extends Mastra
72
72
  abstract authorizeUser(user: TUser, request: MastraAuthRequest): Promise<boolean> | boolean;
73
73
  protected registerOptions(opts?: MastraAuthProviderOptions<TUser>): void;
74
74
  }
75
+ export declare function isSSOProvider(p: unknown): p is ISSOProvider;
76
+ export declare function isSessionProvider(p: unknown): p is ISessionProvider;
77
+ export declare function isUserProvider(p: unknown): p is IUserProvider;
78
+ export declare function isCredentialsProvider(p: unknown): p is ICredentialsProvider;
79
+ export declare function isOrganizationsProvider(p: unknown): p is IOrganizationsProvider;
80
+ export declare function isAuthHttpHandler(p: unknown): p is IAuthHttpHandler;
81
+ export declare function hasAuthInit(p: unknown): p is IAuthInit;
75
82
  export declare class CompositeAuth extends MastraAuthProvider implements ISSOProvider<User>, ISessionProvider<Session>, IUserProvider<User> {
76
83
  private providers;
77
84
  private authenticatedProviderByObject;
@@ -36,6 +36,7 @@ export declare class MastraAuthOkta extends MastraAuthProvider<OktaUser> impleme
36
36
  protected issuer: string;
37
37
  protected endpointBase: string;
38
38
  protected redirectUri: string;
39
+ protected audience: string | string[];
39
40
  protected scopes: string[];
40
41
  protected cookieName: string;
41
42
  protected cookieMaxAge: number;
@@ -1 +1 @@
1
- {"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../src/auth-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,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