@mastra/auth-cloud 1.2.2-alpha.0 → 1.2.3-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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @mastra/auth-cloud
2
2
 
3
+ ## 1.2.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed a race condition in the Mastra Cloud auth provider where two users signing in with SSO at the same time could receive each other's PKCE verifier cookies. Login state is now tracked per request, keyed by the OAuth state parameter, so concurrent logins can no longer cross-wire cookies. Fixes [#20203](https://github.com/mastra-ai/mastra/issues/20203) ([#20233](https://github.com/mastra-ai/mastra/pull/20233))
8
+
9
+ ## 1.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [[`705ff39`](https://github.com/mastra-ai/mastra/commit/705ff3969e57214ff2fdaf3815d751dd558886ed)]:
14
+ - @mastra/auth@1.1.2
15
+
3
16
  ## 1.2.2-alpha.0
4
17
 
5
18
  ### Patch Changes
@@ -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", "heartbeats", "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-workspaces", "system", "tool-providers", "tools", "vector", "vectors", "workflows", "workspaces"];
14
14
  /**
15
15
  * Resource type union.
16
16
  */
@@ -70,8 +70,6 @@ export declare const PERMISSION_PATTERNS: {
70
70
  readonly 'embedders:*': "embedders:*";
71
71
  /** Full access to experiments */
72
72
  readonly 'experiments:*': "experiments:*";
73
- /** Full access to heartbeats */
74
- readonly 'heartbeats:*': "heartbeats:*";
75
73
  /** Full access to infrastructure */
76
74
  readonly 'infrastructure:*': "infrastructure:*";
77
75
  /** Full access to logs */
@@ -160,14 +158,6 @@ export declare const PERMISSION_PATTERNS: {
160
158
  readonly 'embedders:read': "embedders:read";
161
159
  /** View experiments */
162
160
  readonly 'experiments:read': "experiments:read";
163
- /** Delete heartbeats */
164
- readonly 'heartbeats:delete': "heartbeats:delete";
165
- /** Execute heartbeats */
166
- readonly 'heartbeats:execute': "heartbeats:execute";
167
- /** View heartbeats */
168
- readonly 'heartbeats:read': "heartbeats:read";
169
- /** Create and modify heartbeats */
170
- readonly 'heartbeats:write': "heartbeats:write";
171
161
  /** View infrastructure */
172
162
  readonly 'infrastructure:read': "infrastructure:read";
173
163
  /** View logs */
@@ -196,6 +186,8 @@ export declare const PERMISSION_PATTERNS: {
196
186
  readonly 'processors:execute': "processors:execute";
197
187
  /** View processors */
198
188
  readonly 'processors:read': "processors:read";
189
+ /** Delete schedules */
190
+ readonly 'schedules:delete': "schedules:delete";
199
191
  /** Execute schedules */
200
192
  readonly 'schedules:execute': "schedules:execute";
201
193
  /** View schedules */
@@ -313,7 +305,7 @@ export type PermissionPattern = keyof typeof PERMISSION_PATTERNS;
313
305
  /**
314
306
  * All valid resource:action permission combinations (excludes wildcards).
315
307
  */
316
- 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", "heartbeats:delete", "heartbeats:execute", "heartbeats:read", "heartbeats:write", "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: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"];
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"];
317
309
  /**
318
310
  * Specific permission type (e.g., 'agents:read', 'workflows:execute').
319
311
  */
@@ -369,14 +361,6 @@ export declare const MastraFGAPermissions: {
369
361
  readonly EMBEDDERS_READ: "embedders:read";
370
362
  /** View experiments */
371
363
  readonly EXPERIMENTS_READ: "experiments:read";
372
- /** Delete heartbeats */
373
- readonly HEARTBEATS_DELETE: "heartbeats:delete";
374
- /** Execute heartbeats */
375
- readonly HEARTBEATS_EXECUTE: "heartbeats:execute";
376
- /** View heartbeats */
377
- readonly HEARTBEATS_READ: "heartbeats:read";
378
- /** Create and modify heartbeats */
379
- readonly HEARTBEATS_WRITE: "heartbeats:write";
380
364
  /** View infrastructure */
381
365
  readonly INFRASTRUCTURE_READ: "infrastructure:read";
382
366
  /** View logs */
@@ -405,6 +389,8 @@ export declare const MastraFGAPermissions: {
405
389
  readonly PROCESSORS_EXECUTE: "processors:execute";
406
390
  /** View processors */
407
391
  readonly PROCESSORS_READ: "processors:read";
392
+ /** Delete schedules */
393
+ readonly SCHEDULES_DELETE: "schedules:delete";
408
394
  /** Execute schedules */
409
395
  readonly SCHEDULES_EXECUTE: "schedules:execute";
410
396
  /** View schedules */
@@ -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;
@@ -91,10 +91,11 @@ export declare class MastraCloudAuthProvider extends MastraAuthProvider<CloudUse
91
91
  */
92
92
  authorizeUser(user: CloudUser): boolean;
93
93
  /**
94
- * Cached login result for getLoginCookies() to retrieve cookies.
94
+ * Cached login results for getLoginCookies() to retrieve cookies.
95
+ * Keyed by the OAuth state parameter to prevent race conditions.
95
96
  * @internal
96
97
  */
97
- private _lastLoginResult;
98
+ private _loginResults;
98
99
  /**
99
100
  * Get URL to redirect user to for SSO login.
100
101
  *
@@ -107,9 +108,11 @@ export declare class MastraCloudAuthProvider extends MastraAuthProvider<CloudUse
107
108
  * Get cookies to set during login redirect (PKCE verifier).
108
109
  * Must be called after getLoginUrl() in same request.
109
110
  *
111
+ * @param _redirectUri - OAuth callback URL
112
+ * @param state - State parameter
110
113
  * @returns Array of Set-Cookie header values
111
114
  */
112
- getLoginCookies(): string[] | undefined;
115
+ getLoginCookies(_redirectUri: string, state: string): string[] | undefined;
113
116
  /**
114
117
  * Handle OAuth callback, exchange code for tokens and user.
115
118
  *
@@ -1 +1 @@
1
- {"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../src/auth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,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C,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAazF;;;;;OAKG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAYjE;;;;OAIG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;;;;;OAMG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAIhE;;;;;OAKG;IACH,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAIxD;;;;;OAKG;IACH,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAI3D;;;;OAIG;IACH,sBAAsB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQhD;;;;;OAKG;IACG,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAYjE;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;CAG1D"}
package/dist/index.cjs CHANGED
@@ -617,7 +617,7 @@ var MastraBase = class {
617
617
  }
618
618
  };
619
619
 
620
- // ../../packages/_internals/auth/dist/chunk-7GLKLOU3.js
620
+ // ../../packages/_internals/auth/dist/chunk-NJOKT6V5.js
621
621
  var MastraAuthProvider = class extends MastraBase {
622
622
  protected;
623
623
  public;
@@ -727,10 +727,11 @@ var MastraCloudAuthProvider = class extends MastraAuthProvider {
727
727
  // ISSOProvider Implementation
728
728
  // ============================================================================
729
729
  /**
730
- * Cached login result for getLoginCookies() to retrieve cookies.
730
+ * Cached login results for getLoginCookies() to retrieve cookies.
731
+ * Keyed by the OAuth state parameter to prevent race conditions.
731
732
  * @internal
732
733
  */
733
- _lastLoginResult = null;
734
+ _loginResults = /* @__PURE__ */ new Map();
734
735
  /**
735
736
  * Get URL to redirect user to for SSO login.
736
737
  *
@@ -757,19 +758,28 @@ var MastraCloudAuthProvider = class extends MastraAuthProvider {
757
758
  returnTo: postLoginRedirect,
758
759
  requestOrigin: origin
759
760
  });
760
- this._lastLoginResult = result;
761
+ if (this._loginResults.size > 100) {
762
+ const firstKey = this._loginResults.keys().next().value;
763
+ if (firstKey) this._loginResults.delete(firstKey);
764
+ }
765
+ this._loginResults.set(state, result);
761
766
  return result.url;
762
767
  }
763
768
  /**
764
769
  * Get cookies to set during login redirect (PKCE verifier).
765
770
  * Must be called after getLoginUrl() in same request.
766
771
  *
772
+ * @param _redirectUri - OAuth callback URL
773
+ * @param state - State parameter
767
774
  * @returns Array of Set-Cookie header values
768
775
  */
769
- getLoginCookies() {
770
- const cookies = this._lastLoginResult?.cookies;
771
- this._lastLoginResult = null;
772
- return cookies;
776
+ getLoginCookies(_redirectUri, state) {
777
+ const result = this._loginResults.get(state);
778
+ if (result) {
779
+ this._loginResults.delete(state);
780
+ return result.cookies;
781
+ }
782
+ return void 0;
773
783
  }
774
784
  /**
775
785
  * Handle OAuth callback, exchange code for tokens and user.
@@ -936,7 +946,7 @@ var MastraCloudAuthProvider = class extends MastraAuthProvider {
936
946
  }
937
947
  };
938
948
 
939
- // ../../packages/_internals/auth/dist/chunk-GVS7OL46.js
949
+ // ../../packages/_internals/auth/dist/chunk-LZCWL5CT.js
940
950
  var RESOURCE_EXPANSIONS = {
941
951
  stored: [
942
952
  "stored-agents",