@mastra/auth-cloud 1.2.8 → 1.2.9-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/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
- 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
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/permissions.generated.d.ts +12 -2
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/index.d.ts +15 -0
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/provider/index.d.ts +74 -2
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/types/index.d.ts +7 -0
- package/dist/auth-provider.d.ts +9 -4
- package/dist/auth-provider.d.ts.map +1 -1
- package/dist/index.cjs +57 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -1
- package/dist/index.js.map +1 -1
- package/dist/rbac/rbac-provider.d.ts +1 -1
- package/package.json +8 -8
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/capabilities.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/rbac/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/rbac/static.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/roles.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/fga-check.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/acl.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/fga.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/rbac.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/user.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/license.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/cookie.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/memory.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/package.json +0 -0
|
@@ -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 {
|
|
315
|
-
//# sourceMappingURL=index-
|
|
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
|
*/
|
package/dist/auth-provider.d.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @packageDocumentation
|
|
8
8
|
*/
|
|
9
|
-
import type { IUserProvider, ISSOProvider, ISessionProvider, MastraAuthRequest, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth/dist/index.js';
|
|
10
|
-
import type { EEUser } from './_types/@internal_auth/dist/ee/index.js';
|
|
11
|
-
import type { MastraAuthProviderOptions } from './_types/@internal_auth/dist/provider/index.js';
|
|
12
|
-
import { MastraAuthProvider } from './_types/@internal_auth/dist/provider/index.js';
|
|
9
|
+
import type { IUserProvider, ISSOProvider, ISessionProvider, MastraAuthRequest, MastraUser, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth@0.0.36/dist/index.js';
|
|
10
|
+
import type { EEUser } from './_types/@internal_auth@0.0.36/dist/ee/index.js';
|
|
11
|
+
import type { MastraAuthProviderOptions } from './_types/@internal_auth@0.0.36/dist/provider/index.js';
|
|
12
|
+
import { MastraAuthProvider } from './_types/@internal_auth@0.0.36/dist/provider/index.js';
|
|
13
13
|
import type { CloudUser } from './types.js';
|
|
14
14
|
/**
|
|
15
15
|
* Configuration options for MastraCloudAuthProvider.
|
|
@@ -84,6 +84,11 @@ export declare class MastraCloudAuthProvider extends MastraAuthProvider<CloudUse
|
|
|
84
84
|
* @returns True if user has valid id
|
|
85
85
|
*/
|
|
86
86
|
authorizeUser(user: CloudUser): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Normalize the Cloud user; the default normalization cannot see the
|
|
89
|
+
* `avatar` field (it expects `avatarUrl`/`picture`).
|
|
90
|
+
*/
|
|
91
|
+
toMastraUser(user: CloudUser): MastraUser;
|
|
87
92
|
/**
|
|
88
93
|
* Cached login results for getLoginCookies() to retrieve cookies.
|
|
89
94
|
* Keyed by the OAuth state parameter to prevent race conditions.
|
|
@@ -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,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../src/auth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAy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;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAExD;CACF"}
|
package/dist/index.cjs
CHANGED
|
@@ -950,6 +950,41 @@ var MastraBase = class {
|
|
|
950
950
|
}
|
|
951
951
|
};
|
|
952
952
|
// ../../packages/_internals/auth/dist/provider/index.js
|
|
953
|
+
function pickString(...values) {
|
|
954
|
+
for (const value of values) if (typeof value === "string" && value.trim()) return value;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Normalize an arbitrary provider-specific user object to the stable
|
|
958
|
+
* {@link MastraUser} shape surfaced to `DynamicArgument` callbacks.
|
|
959
|
+
*
|
|
960
|
+
* Picks `id` from `id`/`sub`/`userId` (numeric ids are stringified),
|
|
961
|
+
* `avatarUrl` from `avatarUrl`/`picture`, and passes `name`/`email`/`role`
|
|
962
|
+
* through when they are non-empty strings.
|
|
963
|
+
*
|
|
964
|
+
* @throws when no id can be derived — override `toMastraUser()` on the auth
|
|
965
|
+
* provider for user shapes this default cannot handle.
|
|
966
|
+
*/
|
|
967
|
+
function normalizeMastraUser(user) {
|
|
968
|
+
if (typeof user === "string" && user.trim()) return { id: user };
|
|
969
|
+
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.`);
|
|
970
|
+
const record = user;
|
|
971
|
+
const rawId = [
|
|
972
|
+
record.id,
|
|
973
|
+
record.sub,
|
|
974
|
+
record.userId
|
|
975
|
+
].find((value) => typeof value === "string" && value.trim() || typeof value === "number");
|
|
976
|
+
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.");
|
|
977
|
+
const normalized = { id: typeof rawId === "number" ? String(rawId) : rawId };
|
|
978
|
+
const name = pickString(record.name);
|
|
979
|
+
const email = pickString(record.email);
|
|
980
|
+
const avatarUrl = pickString(record.avatarUrl, record.picture);
|
|
981
|
+
const role = pickString(record.role);
|
|
982
|
+
if (name) normalized.name = name;
|
|
983
|
+
if (email) normalized.email = email;
|
|
984
|
+
if (avatarUrl) normalized.avatarUrl = avatarUrl;
|
|
985
|
+
if (role) normalized.role = role;
|
|
986
|
+
return normalized;
|
|
987
|
+
}
|
|
953
988
|
var MastraAuthProvider = class extends MastraBase {
|
|
954
989
|
protected;
|
|
955
990
|
public;
|
|
@@ -963,6 +998,18 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
963
998
|
this.public = options?.public;
|
|
964
999
|
if (options?.mapUserToResourceId) this.mapUserToResourceId = options.mapUserToResourceId;
|
|
965
1000
|
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Normalize the authenticated provider-specific user to the stable
|
|
1003
|
+
* {@link MastraUser} shape surfaced to `DynamicArgument` callbacks as the
|
|
1004
|
+
* optional `user` argument.
|
|
1005
|
+
*
|
|
1006
|
+
* The default implementation handles common user shapes (see
|
|
1007
|
+
* {@link normalizeMastraUser}); override it when your provider's user type
|
|
1008
|
+
* needs custom mapping.
|
|
1009
|
+
*/
|
|
1010
|
+
toMastraUser(user) {
|
|
1011
|
+
return normalizeMastraUser(user);
|
|
1012
|
+
}
|
|
966
1013
|
registerOptions(opts) {
|
|
967
1014
|
if (opts?.authorizeUser) this.authorizeUser = opts.authorizeUser.bind(this);
|
|
968
1015
|
if (opts?.mapUserToResourceId) this.mapUserToResourceId = opts.mapUserToResourceId;
|
|
@@ -970,7 +1017,7 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
970
1017
|
if (opts?.public) this.public = opts.public;
|
|
971
1018
|
}
|
|
972
1019
|
};
|
|
973
|
-
// ../../packages/_internals/auth/dist/ee-
|
|
1020
|
+
// ../../packages/_internals/auth/dist/ee-iTj2bRDt.js
|
|
974
1021
|
/**
|
|
975
1022
|
* FGA enforcement utility for checking fine-grained authorization.
|
|
976
1023
|
*
|
|
@@ -1175,6 +1222,15 @@ var MastraCloudAuthProvider = class extends MastraAuthProvider {
|
|
|
1175
1222
|
return !!user?.id;
|
|
1176
1223
|
}
|
|
1177
1224
|
/**
|
|
1225
|
+
* Normalize the Cloud user; the default normalization cannot see the
|
|
1226
|
+
* `avatar` field (it expects `avatarUrl`/`picture`).
|
|
1227
|
+
*/
|
|
1228
|
+
toMastraUser(user) {
|
|
1229
|
+
const normalized = normalizeMastraUser(user);
|
|
1230
|
+
if (!normalized.avatarUrl && user.avatar) normalized.avatarUrl = user.avatar;
|
|
1231
|
+
return normalized;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1178
1234
|
* Cached login results for getLoginCookies() to retrieve cookies.
|
|
1179
1235
|
* Keyed by the OAuth state parameter to prevent race conditions.
|
|
1180
1236
|
* @internal
|