@mastra/auth-okta 0.2.6-alpha.0 → 0.3.0-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.
Files changed (32) hide show
  1. package/dist/_types/{@internal_auth/dist/_types/@internal_core → @internal_auth@0.0.36/dist/_types/@internal_core@0.1.4}/dist/base/index.d.ts +1 -1
  2. package/dist/_types/{@internal_auth/dist/_types/@internal_core/dist/index-TNVgGNjs.d.ts → @internal_auth@0.0.36/dist/_types/@internal_core@0.1.4/dist/index-Diz1p9N7.d.ts} +3 -2
  3. package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/permissions.generated.d.ts +12 -2
  4. package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/index.d.ts +15 -0
  5. package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/provider/index.d.ts +74 -2
  6. package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/types/index.d.ts +7 -0
  7. package/dist/auth-provider.d.ts +5 -2
  8. package/dist/auth-provider.d.ts.map +1 -1
  9. package/dist/index.cjs +52 -1
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +52 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/rbac-provider.d.ts +1 -1
  14. package/dist/types.d.ts +1 -1
  15. package/package.json +7 -7
  16. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/capabilities.d.ts +0 -0
  17. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/index.d.ts +0 -0
  18. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/rbac/index.d.ts +0 -0
  19. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/rbac/static.d.ts +0 -0
  20. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/roles.d.ts +0 -0
  21. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/fga-check.d.ts +0 -0
  22. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/index.d.ts +0 -0
  23. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/acl.d.ts +0 -0
  24. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/fga.d.ts +0 -0
  25. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/index.d.ts +0 -0
  26. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/rbac.d.ts +0 -0
  27. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/user.d.ts +0 -0
  28. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/license.d.ts +0 -0
  29. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/cookie.d.ts +0 -0
  30. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/index.d.ts +0 -0
  31. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/memory.d.ts +0 -0
  32. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/package.json +0 -0
@@ -1,4 +1,4 @@
1
- import { i as IMastraLogger, u as RegisteredLogger } from "../index-TNVgGNjs.js";
1
+ import { i as IMastraLogger, u as RegisteredLogger } from "../index-Diz1p9N7.js";
2
2
  export declare class MastraBase {
3
3
  #private;
4
4
  component: RegisteredLogger;
@@ -90,6 +90,7 @@ declare function exportTrackedException(ctx: LoggerAdapterContext | undefined, e
90
90
  * so the derived record preserves all context from the native call.
91
91
  */
92
92
  declare function buildLogRecordData(args: unknown[]): Record<string, unknown> | undefined;
93
+ declare const noopLogger: IMastraLogger;
93
94
  declare const RegisteredLogger: {
94
95
  readonly AGENT: 'AGENT';
95
96
  readonly OBSERVABILITY: 'OBSERVABILITY';
@@ -311,5 +312,5 @@ declare class ConsoleLogger extends MastraLogger {
311
312
  hasMore: boolean;
312
313
  }>;
313
314
  }
314
- export { buildLogRecordData as _, LogFilter as a, LoggerTransport as c, createCustomTransport as d, AdaptableLogger as f, TraceFields as g, LoggerAdapterOptions as h, IMastraLogger as i, MastraLogger as l, LoggerAdapterContext as m, ConsoleLogger as n, LogFilterContext as o, AdapterLogSink as p, ConsoleLoggerOptions as r, LogLevel as s, BaseLogMessage as t, RegisteredLogger as u, exportTrackedException as v, isAdaptableLogger as y };
315
- //# sourceMappingURL=index-TNVgGNjs.d.ts.map
315
+ export { TraceFields as _, LogFilter as a, isAdaptableLogger as b, LoggerTransport as c, createCustomTransport as d, noopLogger as f, LoggerAdapterOptions as g, LoggerAdapterContext as h, IMastraLogger as i, MastraLogger as l, AdapterLogSink as m, ConsoleLogger as n, LogFilterContext as o, AdaptableLogger as p, ConsoleLoggerOptions as r, LogLevel as s, BaseLogMessage as t, RegisteredLogger as u, buildLogRecordData as v, exportTrackedException as y };
316
+ //# sourceMappingURL=index-Diz1p9N7.d.ts.map
@@ -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-workflows', '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', 'knowledge', '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
  */
@@ -72,6 +72,8 @@ export declare const PERMISSION_PATTERNS: {
72
72
  readonly 'experiments:*': 'experiments:*';
73
73
  /** Full access to infrastructure */
74
74
  readonly 'infrastructure:*': 'infrastructure:*';
75
+ /** Full access to knowledge */
76
+ readonly 'knowledge:*': 'knowledge:*';
75
77
  /** Full access to logs */
76
78
  readonly 'logs:*': 'logs:*';
77
79
  /** Full access to MCP servers */
@@ -142,6 +144,8 @@ export declare const PERMISSION_PATTERNS: {
142
144
  readonly 'agents:write': 'agents:write';
143
145
  /** View auth */
144
146
  readonly 'auth:read': 'auth:read';
147
+ /** Execute background tasks */
148
+ readonly 'background-tasks:execute': 'background-tasks:execute';
145
149
  /** View background tasks */
146
150
  readonly 'background-tasks:read': 'background-tasks:read';
147
151
  /** View channels */
@@ -164,6 +168,8 @@ export declare const PERMISSION_PATTERNS: {
164
168
  readonly 'experiments:read': 'experiments:read';
165
169
  /** View infrastructure */
166
170
  readonly 'infrastructure:read': 'infrastructure:read';
171
+ /** View knowledge */
172
+ readonly 'knowledge:read': 'knowledge:read';
167
173
  /** View logs */
168
174
  readonly 'logs:read': 'logs:read';
169
175
  /** Execute MCP servers */
@@ -315,7 +321,7 @@ export type PermissionPattern = keyof typeof PERMISSION_PATTERNS;
315
321
  /**
316
322
  * All valid resource:action permission combinations (excludes wildcards).
317
323
  */
318
- 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:delete', 'experiments:read', 'infrastructure:read', 'logs:read', 'mcp:execute', 'mcp:read', 'mcp:write', 'memory:delete', 'memory:execute', 'memory:read', 'memory:write', 'observability:delete', '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'];
324
+ 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:execute', 'background-tasks:read', 'channels:read', 'channels:write', 'datasets:delete', 'datasets:execute', 'datasets:read', 'datasets:write', 'embedders:read', 'experiments:delete', 'experiments:read', 'infrastructure:read', 'knowledge:read', 'logs:read', 'mcp:execute', 'mcp:read', 'mcp:write', 'memory:delete', 'memory:execute', 'memory:read', 'memory:write', 'observability:delete', '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'];
319
325
  /**
320
326
  * Specific permission type (e.g., 'agents:read', 'workflows:execute').
321
327
  */
@@ -353,6 +359,8 @@ export declare const MastraFGAPermissions: {
353
359
  readonly AGENTS_WRITE: 'agents:write';
354
360
  /** View auth */
355
361
  readonly AUTH_READ: 'auth:read';
362
+ /** Execute background tasks */
363
+ readonly BACKGROUND_TASKS_EXECUTE: 'background-tasks:execute';
356
364
  /** View background tasks */
357
365
  readonly BACKGROUND_TASKS_READ: 'background-tasks:read';
358
366
  /** View channels */
@@ -375,6 +383,8 @@ export declare const MastraFGAPermissions: {
375
383
  readonly EXPERIMENTS_READ: 'experiments:read';
376
384
  /** View infrastructure */
377
385
  readonly INFRASTRUCTURE_READ: 'infrastructure:read';
386
+ /** View knowledge */
387
+ readonly KNOWLEDGE_READ: 'knowledge:read';
378
388
  /** View logs */
379
389
  readonly LOGS_READ: 'logs:read';
380
390
  /** Execute MCP servers */
@@ -14,7 +14,22 @@ export interface User {
14
14
  name?: string;
15
15
  /** Avatar URL */
16
16
  avatarUrl?: string;
17
+ /**
18
+ * Primary role, when the auth provider or a configured RBAC provider
19
+ * supplies one. `undefined` means the auth setup has no role concept —
20
+ * not that the user lacks permissions.
21
+ */
22
+ role?: string;
17
23
  }
24
+ /**
25
+ * Authenticated end user, normalized to a stable shape.
26
+ *
27
+ * Produced by `MastraAuthProvider.toMastraUser()` at authentication time and
28
+ * surfaced to `DynamicArgument` callbacks as the optional `user` argument.
29
+ * The raw provider-specific user object remains available on the request
30
+ * context under the `mastra__user` key.
31
+ */
32
+ export type MastraUser = User;
18
33
  /**
19
34
  * Provider interface for user awareness in Studio.
20
35
  *
@@ -1,6 +1,18 @@
1
- import { MastraBase } from '../_types/@internal_core/dist/base/index.js';
2
- import type { CredentialsResult, IAuthHttpHandler, IAuthInit, ICredentialsProvider, IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, Session, SSOCallbackResult, SSOLoginConfig, User } from '..';
1
+ import { MastraBase } from '../_types/@internal_core@0.1.4/dist/base/index.js';
2
+ import type { CredentialsResult, IAuthHttpHandler, IAuthInit, ICredentialsProvider, IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, MastraUser, Session, SSOCallbackResult, SSOLoginConfig, User } from '..';
3
3
  import type { AuthorizeUserFn, MastraAuthConfig, MastraAuthRequest } from '../types/index.js';
4
+ /**
5
+ * Normalize an arbitrary provider-specific user object to the stable
6
+ * {@link MastraUser} shape surfaced to `DynamicArgument` callbacks.
7
+ *
8
+ * Picks `id` from `id`/`sub`/`userId` (numeric ids are stringified),
9
+ * `avatarUrl` from `avatarUrl`/`picture`, and passes `name`/`email`/`role`
10
+ * through when they are non-empty strings.
11
+ *
12
+ * @throws when no id can be derived — override `toMastraUser()` on the auth
13
+ * provider for user shapes this default cannot handle.
14
+ */
15
+ export declare function normalizeMastraUser(user: unknown): MastraUser;
4
16
  export interface MastraAuthProviderOptions<TUser = unknown> {
5
17
  name?: string;
6
18
  authorizeUser?: AuthorizeUserFn<TUser>;
@@ -50,6 +62,11 @@ export interface IMastraAuthProvider<TUser = unknown> {
50
62
  * Map an authenticated user to a memory resource id
51
63
  */
52
64
  mapUserToResourceId?(user: TUser): string | undefined | null;
65
+ /**
66
+ * Normalize the authenticated provider-specific user to the stable
67
+ * `MastraUser` shape surfaced to `DynamicArgument` callbacks.
68
+ */
69
+ toMastraUser?(user: TUser): MastraUser;
53
70
  /**
54
71
  * Return response headers (typically `Set-Cookie` for a rotated session)
55
72
  * that the provider accumulated while handling this request and clear them
@@ -58,7 +75,32 @@ export interface IMastraAuthProvider<TUser = unknown> {
58
75
  * reach the browser.
59
76
  */
60
77
  consumePendingResponseHeaders?(request: MastraAuthRequest): Record<string, string> | undefined;
78
+ /**
79
+ * OAuth 2.0 Protected Resource Metadata (RFC 9728) hints, used by the built-in MCP server's
80
+ * `/.well-known/oauth-protected-resource` endpoint when `server.mcp.oauth` does not set them.
81
+ */
82
+ getOAuthMetadata?(): MastraAuthOAuthMetadata | undefined;
83
+ /**
84
+ * Whether the token that authenticated `user` was issued for `audience` (its `aud` claim includes it).
85
+ * `user` is the value returned by `authenticateToken`. Called by the built-in MCP server when
86
+ * `server.mcp.oauth.resource` is set.
87
+ */
88
+ verifyAudience?(user: TUser, audience: string): boolean | Promise<boolean>;
89
+ }
90
+ /** Authorization server hints for MCP clients (RFC 9728). */
91
+ export interface MastraAuthOAuthMetadata {
92
+ /** Issuer URLs of the authorization servers that issue tokens accepted by this provider. */
93
+ authorizationServers?: string[];
94
+ /** OAuth scopes the provider understands. */
95
+ scopesSupported?: string[];
61
96
  }
97
+ /** Whether a JWT `aud` claim (string or array) includes `audience`. */
98
+ export declare function jwtAudienceIncludes(aud: unknown, audience: string): boolean;
99
+ /**
100
+ * JWT claims as the authenticated user. OIDC tokens name the user in `sub`, while RBAC and FGA look the user up
101
+ * by `id`, so `id` is filled from `sub` when the token has no `id` claim of its own.
102
+ */
103
+ export declare function withSubjectAsId<T extends object>(claims: T): T;
62
104
  export declare abstract class MastraAuthProvider<TUser = unknown> extends MastraBase implements IMastraAuthProvider<TUser> {
63
105
  protected?: MastraAuthConfig['protected'];
64
106
  public?: MastraAuthConfig['public'];
@@ -78,6 +120,16 @@ export declare abstract class MastraAuthProvider<TUser = unknown> extends Mastra
78
120
  * @returns The authorization result
79
121
  */
80
122
  abstract authorizeUser(user: TUser, request: MastraAuthRequest): Promise<boolean> | boolean;
123
+ /**
124
+ * Normalize the authenticated provider-specific user to the stable
125
+ * {@link MastraUser} shape surfaced to `DynamicArgument` callbacks as the
126
+ * optional `user` argument.
127
+ *
128
+ * The default implementation handles common user shapes (see
129
+ * {@link normalizeMastraUser}); override it when your provider's user type
130
+ * needs custom mapping.
131
+ */
132
+ toMastraUser(user: TUser): MastraUser;
81
133
  protected registerOptions(opts?: MastraAuthProviderOptions<TUser>): void;
82
134
  }
83
135
  export declare function isSSOProvider(p: unknown): p is ISSOProvider;
@@ -95,6 +147,13 @@ export declare class CompositeAuth extends MastraAuthProvider implements ISSOPro
95
147
  private findProvider;
96
148
  private rememberAuthenticatedProvider;
97
149
  private takeAuthenticatedProvider;
150
+ private peekAuthenticatedProvider;
151
+ /**
152
+ * Delegate normalization to the provider that authenticated this user.
153
+ * Falls back to the default normalization when the winning provider is
154
+ * unknown or predates `toMastraUser`.
155
+ */
156
+ toMastraUser(user: unknown): MastraUser;
98
157
  private mapAuthenticatedUserToResourceId;
99
158
  /**
100
159
  * True if any provider is MastraCloudAuth (exempt from license requirement).
@@ -106,6 +165,19 @@ export declare class CompositeAuth extends MastraAuthProvider implements ISSOPro
106
165
  get isSimpleAuth(): boolean;
107
166
  authenticateToken(token: string, request: MastraAuthRequest): Promise<unknown | null>;
108
167
  consumePendingResponseHeaders(request: MastraAuthRequest): Record<string, string> | undefined;
168
+ /** The wrapped provider that authenticated `user`, or undefined when it can't be determined. */
169
+ getAuthenticatedProvider(user: unknown): IMastraAuthProvider | undefined;
170
+ /** The wrapped providers, in the order they are tried. */
171
+ getProviders(): readonly IMastraAuthProvider[];
172
+ /** Union of the wrapped providers' OAuth metadata. */
173
+ getOAuthMetadata(): MastraAuthOAuthMetadata | undefined;
174
+ /**
175
+ * Delegates to the provider that authenticated `user`. Returns true (audience not enforced) when that
176
+ * provider has no `verifyAudience`. When the authenticating provider can't be determined (for example the
177
+ * user object was replaced after authentication), returns false if any wrapped provider could check the
178
+ * audience, so the check fails closed.
179
+ */
180
+ verifyAudience(user: unknown, audience: string): Promise<boolean>;
109
181
  authorizeUser(user: unknown, request: MastraAuthRequest): Promise<boolean>;
110
182
  /**
111
183
  * Forward cookie header to SSO provider for PKCE validation.
@@ -1,3 +1,4 @@
1
+ import type { User } from '../index.js';
1
2
  export interface HonoRequestLike {
2
3
  raw?: Request;
3
4
  headers?: Headers | Record<string, string | string[] | undefined>;
@@ -34,6 +35,12 @@ export type MastraAuthConfig<TUser = unknown, TContext = unknown> = {
34
35
  * Maps the authenticated user to a resource ID for memory/thread scoping.
35
36
  */
36
37
  mapUserToResourceId?(user: TUser): string | undefined | null;
38
+ /**
39
+ * Normalizes the authenticated user to the `MastraUser` shape passed to
40
+ * dynamic configuration callbacks as `user`. Defaults to the shared
41
+ * normalization (`id`/`sub`/`userId`, `name`, `email`, `avatarUrl`/`picture`, `role`).
42
+ */
43
+ toMastraUser?(user: TUser): User;
37
44
  /**
38
45
  * Authorization function for the server.
39
46
  */
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * Supports OAuth 2.0 / OIDC login flow with client_secret and session management.
5
5
  */
6
- import type { ISSOProvider, ISessionProvider, IUserProvider, MastraAuthRequest, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth/dist/index.js';
7
- import { MastraAuthProvider } from './_types/@internal_auth/dist/provider/index.js';
6
+ import type { ISSOProvider, ISessionProvider, IUserProvider, MastraAuthRequest, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth@0.0.36/dist/index.js';
7
+ import type { MastraAuthOAuthMetadata } from './_types/@internal_auth@0.0.36/dist/provider/index.js';
8
+ import { MastraAuthProvider } from './_types/@internal_auth@0.0.36/dist/provider/index.js';
8
9
  import type { OktaUser, MastraAuthOktaOptions } from './types.js';
9
10
  /**
10
11
  * Mastra authentication provider for Okta with SSO support.
@@ -44,6 +45,8 @@ export declare class MastraAuthOkta extends MastraAuthProvider<OktaUser> impleme
44
45
  * First tries to read from session cookie, then falls back to Authorization header.
45
46
  */
46
47
  authenticateToken(token: string, request: MastraAuthRequest): Promise<OktaUser | null>;
48
+ /** The Okta authorization server is the authorization server for MCP clients. */
49
+ getOAuthMetadata(): MastraAuthOAuthMetadata;
47
50
  /**
48
51
  * Authorize a user.
49
52
  */
@@ -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,iBAAiB,EACjB,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAoFlE;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cACX,SAAQ,kBAAkB,CAAC,QAAQ,CACnC,YAAW,YAAY,CAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC;IAErF,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC3B,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC7B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M,CAElB;IAED;;OAEG;IACH,WAAW,IAAI,MAAM,CAEpB;IAED;;OAEG;IACH,cAAc,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,SAAS,IAAI,MAAM,CAElB;CACF"}
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let lru_cache = require("lru-cache");
3
3
  let jose = require("jose");
4
- // ../../packages/_internals/auth/dist/ee-CnZdF0Vm.js
4
+ // ../../packages/_internals/auth/dist/ee-iTj2bRDt.js
5
5
  /**
6
6
  * FGA enforcement utility for checking fine-grained authorization.
7
7
  *
@@ -600,6 +600,41 @@ var MastraBase = class {
600
600
  }
601
601
  };
602
602
  // ../../packages/_internals/auth/dist/provider/index.js
603
+ function pickString(...values) {
604
+ for (const value of values) if (typeof value === "string" && value.trim()) return value;
605
+ }
606
+ /**
607
+ * Normalize an arbitrary provider-specific user object to the stable
608
+ * {@link MastraUser} shape surfaced to `DynamicArgument` callbacks.
609
+ *
610
+ * Picks `id` from `id`/`sub`/`userId` (numeric ids are stringified),
611
+ * `avatarUrl` from `avatarUrl`/`picture`, and passes `name`/`email`/`role`
612
+ * through when they are non-empty strings.
613
+ *
614
+ * @throws when no id can be derived — override `toMastraUser()` on the auth
615
+ * provider for user shapes this default cannot handle.
616
+ */
617
+ function normalizeMastraUser(user) {
618
+ if (typeof user === "string" && user.trim()) return { id: user };
619
+ if (user === null || typeof user !== "object") throw new Error(`Unable to normalize authenticated user of type "${typeof user}" to a MastraUser. Override toMastraUser() on your auth provider to supply a normalized user.`);
620
+ const record = user;
621
+ const rawId = [
622
+ record.id,
623
+ record.sub,
624
+ record.userId
625
+ ].find((value) => typeof value === "string" && value.trim() || typeof value === "number");
626
+ if (rawId === void 0) throw new Error("Unable to derive a user id (looked at `id`, `sub`, and `userId`) while normalizing the authenticated user. Override toMastraUser() on your auth provider to supply a normalized user.");
627
+ const normalized = { id: typeof rawId === "number" ? String(rawId) : rawId };
628
+ const name = pickString(record.name);
629
+ const email = pickString(record.email);
630
+ const avatarUrl = pickString(record.avatarUrl, record.picture);
631
+ const role = pickString(record.role);
632
+ if (name) normalized.name = name;
633
+ if (email) normalized.email = email;
634
+ if (avatarUrl) normalized.avatarUrl = avatarUrl;
635
+ if (role) normalized.role = role;
636
+ return normalized;
637
+ }
603
638
  var MastraAuthProvider = class extends MastraBase {
604
639
  protected;
605
640
  public;
@@ -613,6 +648,18 @@ var MastraAuthProvider = class extends MastraBase {
613
648
  this.public = options?.public;
614
649
  if (options?.mapUserToResourceId) this.mapUserToResourceId = options.mapUserToResourceId;
615
650
  }
651
+ /**
652
+ * Normalize the authenticated provider-specific user to the stable
653
+ * {@link MastraUser} shape surfaced to `DynamicArgument` callbacks as the
654
+ * optional `user` argument.
655
+ *
656
+ * The default implementation handles common user shapes (see
657
+ * {@link normalizeMastraUser}); override it when your provider's user type
658
+ * needs custom mapping.
659
+ */
660
+ toMastraUser(user) {
661
+ return normalizeMastraUser(user);
662
+ }
616
663
  registerOptions(opts) {
617
664
  if (opts?.authorizeUser) this.authorizeUser = opts.authorizeUser.bind(this);
618
665
  if (opts?.mapUserToResourceId) this.mapUserToResourceId = opts.mapUserToResourceId;
@@ -806,6 +853,10 @@ var MastraAuthOkta = class extends MastraAuthProvider {
806
853
  return null;
807
854
  }
808
855
  }
856
+ /** The Okta authorization server is the authorization server for MCP clients. */
857
+ getOAuthMetadata() {
858
+ return { authorizationServers: [this.issuer] };
859
+ }
809
860
  /**
810
861
  * Authorize a user.
811
862
  */