@frontmcp/auth 0.0.1 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/authorization/authorization.types.d.ts +236 -0
- package/authorization/authorization.types.d.ts.map +1 -0
- package/authorization/index.d.ts +9 -0
- package/authorization/index.d.ts.map +1 -0
- package/cimd/cimd-redis.cache.d.ts +111 -0
- package/cimd/cimd-redis.cache.d.ts.map +1 -0
- package/cimd/cimd.cache.d.ts +200 -0
- package/cimd/cimd.cache.d.ts.map +1 -0
- package/cimd/cimd.errors.d.ts +124 -0
- package/cimd/cimd.errors.d.ts.map +1 -0
- package/cimd/cimd.logger.d.ts +39 -0
- package/cimd/cimd.logger.d.ts.map +1 -0
- package/cimd/cimd.service.d.ts +88 -0
- package/cimd/cimd.service.d.ts.map +1 -0
- package/cimd/cimd.types.d.ts +178 -0
- package/cimd/cimd.types.d.ts.map +1 -0
- package/cimd/cimd.validator.d.ts +49 -0
- package/cimd/cimd.validator.d.ts.map +1 -0
- package/cimd/index.d.ts +17 -0
- package/cimd/index.d.ts.map +1 -0
- package/esm/index.mjs +4001 -0
- package/esm/package.json +59 -0
- package/index.d.ts +44 -0
- package/index.d.ts.map +1 -0
- package/index.js +4131 -0
- package/jwks/dev-key-persistence.d.ts +70 -0
- package/jwks/dev-key-persistence.d.ts.map +1 -0
- package/jwks/index.d.ts +20 -0
- package/jwks/index.d.ts.map +1 -0
- package/jwks/jwks.service.d.ts +69 -0
- package/jwks/jwks.service.d.ts.map +1 -0
- package/jwks/jwks.types.d.ts +33 -0
- package/jwks/jwks.types.d.ts.map +1 -0
- package/jwks/jwks.utils.d.ts +5 -0
- package/jwks/jwks.utils.d.ts.map +1 -0
- package/package.json +2 -2
- package/session/authorization-vault.d.ts +667 -0
- package/session/authorization-vault.d.ts.map +1 -0
- package/session/authorization.store.d.ts +311 -0
- package/session/authorization.store.d.ts.map +1 -0
- package/session/index.d.ts +19 -0
- package/session/index.d.ts.map +1 -0
- package/session/storage/in-memory-authorization-vault.d.ts +53 -0
- package/session/storage/in-memory-authorization-vault.d.ts.map +1 -0
- package/session/storage/index.d.ts +17 -0
- package/session/storage/index.d.ts.map +1 -0
- package/session/storage/storage-authorization-vault.d.ts +107 -0
- package/session/storage/storage-authorization-vault.d.ts.map +1 -0
- package/session/storage/storage-token-store.d.ts +92 -0
- package/session/storage/storage-token-store.d.ts.map +1 -0
- package/session/token.store.d.ts +39 -0
- package/session/token.store.d.ts.map +1 -0
- package/session/token.vault.d.ts +33 -0
- package/session/token.vault.d.ts.map +1 -0
- package/session/utils/index.d.ts +5 -0
- package/session/utils/index.d.ts.map +1 -0
- package/session/utils/tiny-ttl-cache.d.ts +20 -0
- package/session/utils/tiny-ttl-cache.d.ts.map +1 -0
- package/session/vault-encryption.d.ts +190 -0
- package/session/vault-encryption.d.ts.map +1 -0
- package/ui/base-layout.d.ts +170 -0
- package/ui/base-layout.d.ts.map +1 -0
- package/ui/index.d.ts +10 -0
- package/ui/index.d.ts.map +1 -0
- package/ui/templates.d.ts +134 -0
- package/ui/templates.d.ts.map +1 -0
- package/utils/audience.validator.d.ts +130 -0
- package/utils/audience.validator.d.ts.map +1 -0
- package/utils/index.d.ts +8 -0
- package/utils/index.d.ts.map +1 -0
- package/utils/www-authenticate.utils.d.ts +98 -0
- package/utils/www-authenticate.utils.d.ts.map +1 -0
- package/vault/auth-providers.types.d.ts +262 -0
- package/vault/auth-providers.types.d.ts.map +1 -0
- package/vault/credential-cache.d.ts +98 -0
- package/vault/credential-cache.d.ts.map +1 -0
- package/vault/credential-helpers.d.ts +14 -0
- package/vault/credential-helpers.d.ts.map +1 -0
- package/vault/index.d.ts +10 -0
- package/vault/index.d.ts.map +1 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audience Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates JWT audience claims per RFC 7519 and MCP Authorization spec.
|
|
5
|
+
* The audience (aud) claim identifies the recipients that the JWT is intended for.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Validation result
|
|
9
|
+
*/
|
|
10
|
+
export interface AudienceValidationResult {
|
|
11
|
+
/** Whether the audience is valid */
|
|
12
|
+
valid: boolean;
|
|
13
|
+
/** Error message if invalid */
|
|
14
|
+
error?: string;
|
|
15
|
+
/** Matched audience value (if valid) */
|
|
16
|
+
matchedAudience?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Audience validator options
|
|
20
|
+
*/
|
|
21
|
+
export interface AudienceValidatorOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Expected audience values
|
|
24
|
+
* Token must contain at least one of these audiences
|
|
25
|
+
*/
|
|
26
|
+
expectedAudiences: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether to allow tokens with no audience claim
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
allowNoAudience?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Case-sensitive comparison
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
caseSensitive?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Allow wildcard matching (e.g., *.example.com)
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
allowWildcards?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Validate JWT audience claim
|
|
45
|
+
*
|
|
46
|
+
* @param tokenAudience - The audience claim from the JWT (can be string or array)
|
|
47
|
+
* @param options - Validation options
|
|
48
|
+
* @returns Validation result
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Single expected audience
|
|
53
|
+
* validateAudience('https://api.example.com', {
|
|
54
|
+
* expectedAudiences: ['https://api.example.com'],
|
|
55
|
+
* });
|
|
56
|
+
* // => { valid: true, matchedAudience: 'https://api.example.com' }
|
|
57
|
+
*
|
|
58
|
+
* // Multiple audiences in token
|
|
59
|
+
* validateAudience(['aud1', 'aud2', 'aud3'], {
|
|
60
|
+
* expectedAudiences: ['aud2'],
|
|
61
|
+
* });
|
|
62
|
+
* // => { valid: true, matchedAudience: 'aud2' }
|
|
63
|
+
*
|
|
64
|
+
* // No match
|
|
65
|
+
* validateAudience('wrong-aud', {
|
|
66
|
+
* expectedAudiences: ['expected-aud'],
|
|
67
|
+
* });
|
|
68
|
+
* // => { valid: false, error: 'Token audience does not match expected audiences' }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function validateAudience(tokenAudience: string | string[] | undefined, options: AudienceValidatorOptions): AudienceValidationResult;
|
|
72
|
+
/**
|
|
73
|
+
* Create an audience validator function
|
|
74
|
+
*
|
|
75
|
+
* @param options - Validator options
|
|
76
|
+
* @returns A validation function that takes token audience and returns validation result
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const validator = createAudienceValidator({
|
|
81
|
+
* expectedAudiences: ['https://api.example.com', 'https://api.example.org'],
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* validator('https://api.example.com'); // => { valid: true, ... }
|
|
85
|
+
* validator('wrong-aud'); // => { valid: false, ... }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function createAudienceValidator(options: AudienceValidatorOptions): (audience: string | string[] | undefined) => AudienceValidationResult;
|
|
89
|
+
/**
|
|
90
|
+
* Derive expected audience from the resource URL
|
|
91
|
+
*
|
|
92
|
+
* Per MCP Authorization spec, the audience should typically be the
|
|
93
|
+
* resource server URL (the MCP server URL).
|
|
94
|
+
*
|
|
95
|
+
* @param resourceUrl - The resource server URL
|
|
96
|
+
* @returns Array of expected audiences
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* deriveExpectedAudience('https://api.example.com/v1/mcp');
|
|
101
|
+
* // => ['https://api.example.com/v1/mcp', 'https://api.example.com', 'api.example.com']
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function deriveExpectedAudience(resourceUrl: string): string[];
|
|
105
|
+
/**
|
|
106
|
+
* AudienceValidator class for reusable validation with configuration
|
|
107
|
+
*/
|
|
108
|
+
export declare class AudienceValidator {
|
|
109
|
+
private options;
|
|
110
|
+
constructor(options?: Partial<AudienceValidatorOptions> & {
|
|
111
|
+
expectedAudiences?: string[];
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* Validate an audience claim
|
|
115
|
+
*/
|
|
116
|
+
validate(audience: string | string[] | undefined): AudienceValidationResult;
|
|
117
|
+
/**
|
|
118
|
+
* Add expected audiences
|
|
119
|
+
*/
|
|
120
|
+
addAudiences(...audiences: string[]): void;
|
|
121
|
+
/**
|
|
122
|
+
* Set expected audiences (replace existing)
|
|
123
|
+
*/
|
|
124
|
+
setAudiences(audiences: string[]): void;
|
|
125
|
+
/**
|
|
126
|
+
* Create validator from resource URL
|
|
127
|
+
*/
|
|
128
|
+
static fromResourceUrl(resourceUrl: string, options?: Omit<AudienceValidatorOptions, 'expectedAudiences'>): AudienceValidator;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=audience.validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audience.validator.d.ts","sourceRoot":"","sources":["../../src/utils/audience.validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,oCAAoC;IACpC,KAAK,EAAE,OAAO,CAAC;IACf,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAE5B;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;OAGG;IACH,aAAa,CAAC,EAAE,O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Header, buildInvalidRequestHeader, parseWwwAuthenticate, } from './www-authenticate.utils';
|
|
5
|
+
export type { BearerErrorCode, WwwAuthenticateOptions } from './www-authenticate.utils';
|
|
6
|
+
export { validateAudience, createAudienceValidator, deriveExpectedAudience, AudienceValidator, } from './audience.validator';
|
|
7
|
+
export type { AudienceValidationResult, AudienceValidatorOptions } from './audience.validator';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,uBAAuB,EACvB,uBAAuB,EACvB,4BAA4B,EAC5B,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAExF,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WWW-Authenticate Header Builder
|
|
3
|
+
*
|
|
4
|
+
* Implements RFC 9728 (OAuth 2.0 Protected Resource Metadata) and
|
|
5
|
+
* RFC 6750 (Bearer Token Usage) compliant WWW-Authenticate headers.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Error codes per RFC 6750 Section 3.1
|
|
9
|
+
*/
|
|
10
|
+
export type BearerErrorCode = 'invalid_request' | 'invalid_token' | 'insufficient_scope';
|
|
11
|
+
/**
|
|
12
|
+
* Options for building WWW-Authenticate header
|
|
13
|
+
*/
|
|
14
|
+
export interface WwwAuthenticateOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The resource_metadata URL pointing to the PRM document
|
|
17
|
+
* Per RFC 9728, this is the primary mechanism for resource discovery
|
|
18
|
+
*/
|
|
19
|
+
resourceMetadataUrl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* OAuth 2.0 realm (optional per RFC 6750)
|
|
22
|
+
*/
|
|
23
|
+
realm?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Required scopes for the resource (space-delimited)
|
|
26
|
+
*/
|
|
27
|
+
scope?: string | string[];
|
|
28
|
+
/**
|
|
29
|
+
* Error code when authentication fails
|
|
30
|
+
*/
|
|
31
|
+
error?: BearerErrorCode;
|
|
32
|
+
/**
|
|
33
|
+
* Human-readable error description
|
|
34
|
+
*/
|
|
35
|
+
errorDescription?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Error URI pointing to additional information
|
|
38
|
+
*/
|
|
39
|
+
errorUri?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build a WWW-Authenticate header for Bearer authentication
|
|
43
|
+
*
|
|
44
|
+
* @param options - Header options
|
|
45
|
+
* @returns The formatted WWW-Authenticate header value
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // Basic protected resource metadata header
|
|
50
|
+
* buildWwwAuthenticate({
|
|
51
|
+
* resourceMetadataUrl: 'https://api.example.com/.well-known/oauth-protected-resource',
|
|
52
|
+
* });
|
|
53
|
+
* // => 'Bearer resource_metadata="https://api.example.com/.well-known/oauth-protected-resource"'
|
|
54
|
+
*
|
|
55
|
+
* // With error information
|
|
56
|
+
* buildWwwAuthenticate({
|
|
57
|
+
* resourceMetadataUrl: 'https://api.example.com/.well-known/oauth-protected-resource',
|
|
58
|
+
* error: 'insufficient_scope',
|
|
59
|
+
* scope: ['read', 'write'],
|
|
60
|
+
* errorDescription: 'Additional permissions required',
|
|
61
|
+
* });
|
|
62
|
+
* // => 'Bearer resource_metadata="...", error="insufficient_scope", scope="read write", error_description="..."'
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildWwwAuthenticate(options?: WwwAuthenticateOptions): string;
|
|
66
|
+
/**
|
|
67
|
+
* Build the Protected Resource Metadata URL for a given base URL and path
|
|
68
|
+
*
|
|
69
|
+
* @param baseUrl - The server base URL
|
|
70
|
+
* @param entryPath - The entry path prefix
|
|
71
|
+
* @param routeBase - The route base path
|
|
72
|
+
* @returns The full PRM URL
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildPrmUrl(baseUrl: string, entryPath: string, routeBase: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Build WWW-Authenticate header for unauthorized requests (no token)
|
|
77
|
+
*/
|
|
78
|
+
export declare function buildUnauthorizedHeader(prmUrl: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Build WWW-Authenticate header for invalid token errors
|
|
81
|
+
*/
|
|
82
|
+
export declare function buildInvalidTokenHeader(prmUrl: string, description?: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Build WWW-Authenticate header for insufficient scope errors
|
|
85
|
+
*/
|
|
86
|
+
export declare function buildInsufficientScopeHeader(prmUrl: string, requiredScopes: string[], description?: string): string;
|
|
87
|
+
/**
|
|
88
|
+
* Build WWW-Authenticate header for invalid request errors
|
|
89
|
+
*/
|
|
90
|
+
export declare function buildInvalidRequestHeader(prmUrl: string, description?: string): string;
|
|
91
|
+
/**
|
|
92
|
+
* Parse a WWW-Authenticate header value
|
|
93
|
+
*
|
|
94
|
+
* @param header - The WWW-Authenticate header value
|
|
95
|
+
* @returns Parsed header options
|
|
96
|
+
*/
|
|
97
|
+
export declare function parseWwwAuthenticate(header: string): WwwAuthenticateOptions;
|
|
98
|
+
//# sourceMappingURL=www-authenticate.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"www-authenticate.utils.d.ts","sourceRoot":"","sources":["../../src/utils/www-authenticate.utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAA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
*
|
|
4
|
+
* Types for credential management, provider configuration, and vault operations.
|
|
5
|
+
* These are portable types that can be used across different implementations.
|
|
6
|
+
*/
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import type { Credential, AuthorizationVault } from '../session';
|
|
9
|
+
/**
|
|
10
|
+
* Credential scope determines caching and storage behavior.
|
|
11
|
+
*
|
|
12
|
+
* - `global`: Shared across all sessions and users. Stored with global key.
|
|
13
|
+
* - `user`: Scoped to a specific user. Persists across sessions for same user.
|
|
14
|
+
* - `session`: Scoped to a specific session. Lost when session ends.
|
|
15
|
+
*/
|
|
16
|
+
export type CredentialScope = 'global' | 'user' | 'session';
|
|
17
|
+
export declare const credentialScopeSchema: z.ZodEnum<{
|
|
18
|
+
user: "user";
|
|
19
|
+
global: "global";
|
|
20
|
+
session: "session";
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Loading strategy determines when credentials are acquired.
|
|
24
|
+
*
|
|
25
|
+
* - `eager`: Load at session initialization (blocking)
|
|
26
|
+
* - `lazy`: Load on first access (non-blocking init)
|
|
27
|
+
*/
|
|
28
|
+
export type LoadingStrategy = 'eager' | 'lazy';
|
|
29
|
+
export declare const loadingStrategySchema: z.ZodEnum<{
|
|
30
|
+
lazy: "lazy";
|
|
31
|
+
eager: "eager";
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Options for credential retrieval
|
|
35
|
+
*/
|
|
36
|
+
export interface GetCredentialOptions {
|
|
37
|
+
/** Force refresh even if cached and valid */
|
|
38
|
+
forceRefresh?: boolean;
|
|
39
|
+
/** Required scopes (for OAuth providers) */
|
|
40
|
+
scopes?: string[];
|
|
41
|
+
/** Timeout for credential acquisition in ms */
|
|
42
|
+
timeout?: number;
|
|
43
|
+
}
|
|
44
|
+
export declare const getCredentialOptionsSchema: z.ZodObject<{
|
|
45
|
+
forceRefresh: z.ZodOptional<z.ZodBoolean>;
|
|
46
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
47
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
/**
|
|
50
|
+
* Resolved credential with metadata
|
|
51
|
+
*/
|
|
52
|
+
export interface ResolvedCredential<T extends Credential = Credential> {
|
|
53
|
+
/** The credential data */
|
|
54
|
+
credential: T;
|
|
55
|
+
/** Provider ID that provided this credential */
|
|
56
|
+
providerId: string;
|
|
57
|
+
/** When the credential was acquired (epoch ms) */
|
|
58
|
+
acquiredAt: number;
|
|
59
|
+
/** When the credential expires (epoch ms, if applicable) */
|
|
60
|
+
expiresAt?: number;
|
|
61
|
+
/** Whether the credential is currently valid */
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
/** Scope the credential was resolved at */
|
|
64
|
+
scope: CredentialScope;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Context passed to credential factories
|
|
68
|
+
*/
|
|
69
|
+
export interface CredentialFactoryContext {
|
|
70
|
+
/** Current session ID */
|
|
71
|
+
sessionId: string;
|
|
72
|
+
/** User subject identifier (from JWT sub claim) */
|
|
73
|
+
userSub?: string;
|
|
74
|
+
/** User email */
|
|
75
|
+
userEmail?: string;
|
|
76
|
+
/** User name */
|
|
77
|
+
userName?: string;
|
|
78
|
+
/** App ID requesting the credential */
|
|
79
|
+
appId?: string;
|
|
80
|
+
/** Tool ID requesting the credential (if available) */
|
|
81
|
+
toolId?: string;
|
|
82
|
+
/** Existing credential (for refresh operations) */
|
|
83
|
+
existingCredential?: Credential;
|
|
84
|
+
/** Authorization vault for storage operations */
|
|
85
|
+
vault: AuthorizationVault;
|
|
86
|
+
/** Custom metadata passed during provider registration */
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Credential factory function type.
|
|
91
|
+
* Called to acquire new credentials or refresh existing ones.
|
|
92
|
+
*/
|
|
93
|
+
export type CredentialFactory<T extends Credential = Credential> = (context: CredentialFactoryContext) => Promise<T | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Credential refresh function type.
|
|
96
|
+
* Called specifically for credential rotation/refresh.
|
|
97
|
+
*/
|
|
98
|
+
export type CredentialRefreshFn<T extends Credential = Credential> = (context: CredentialFactoryContext & {
|
|
99
|
+
existingCredential: T;
|
|
100
|
+
}) => Promise<T | null>;
|
|
101
|
+
/**
|
|
102
|
+
* Headers generator function type.
|
|
103
|
+
* Converts a credential to HTTP headers.
|
|
104
|
+
*/
|
|
105
|
+
export type CredentialHeadersFn<T extends Credential = Credential> = (credential: T) => Record<string, string>;
|
|
106
|
+
/**
|
|
107
|
+
* Configuration for registering a credential provider
|
|
108
|
+
*/
|
|
109
|
+
export interface CredentialProviderConfig<T extends Credential = Credential> {
|
|
110
|
+
/** Unique provider name (e.g., 'github', 'openai', 'aws') */
|
|
111
|
+
name: string;
|
|
112
|
+
/** Human-readable description */
|
|
113
|
+
description?: string;
|
|
114
|
+
/** Credential scope - determines storage and caching behavior */
|
|
115
|
+
scope: CredentialScope;
|
|
116
|
+
/** Loading strategy - when to acquire credentials */
|
|
117
|
+
loading: LoadingStrategy;
|
|
118
|
+
/** TTL in milliseconds for cached credentials (0 = no TTL, use credential expiry) */
|
|
119
|
+
cacheTtl?: number;
|
|
120
|
+
/**
|
|
121
|
+
* Factory function to acquire credentials.
|
|
122
|
+
* Called on first access (lazy) or session init (eager).
|
|
123
|
+
*/
|
|
124
|
+
factory: CredentialFactory<T>;
|
|
125
|
+
/**
|
|
126
|
+
* Optional refresh function for credential rotation.
|
|
127
|
+
* If not provided, factory is called on refresh.
|
|
128
|
+
*/
|
|
129
|
+
refresh?: CredentialRefreshFn<T>;
|
|
130
|
+
/**
|
|
131
|
+
* Optional headers generator from credential.
|
|
132
|
+
* If not provided, uses default header generation logic.
|
|
133
|
+
*/
|
|
134
|
+
toHeaders?: CredentialHeadersFn<T>;
|
|
135
|
+
/** Custom metadata to pass to factory */
|
|
136
|
+
metadata?: Record<string, unknown>;
|
|
137
|
+
/** Required for this provider to be available (default: false) */
|
|
138
|
+
required?: boolean;
|
|
139
|
+
}
|
|
140
|
+
export declare const credentialProviderConfigSchema: z.ZodObject<{
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
description: z.ZodOptional<z.ZodString>;
|
|
143
|
+
scope: z.ZodEnum<{
|
|
144
|
+
user: "user";
|
|
145
|
+
global: "global";
|
|
146
|
+
session: "session";
|
|
147
|
+
}>;
|
|
148
|
+
loading: z.ZodEnum<{
|
|
149
|
+
lazy: "lazy";
|
|
150
|
+
eager: "eager";
|
|
151
|
+
}>;
|
|
152
|
+
cacheTtl: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
factory: z.ZodAny;
|
|
154
|
+
refresh: z.ZodOptional<z.ZodAny>;
|
|
155
|
+
toHeaders: z.ZodOptional<z.ZodAny>;
|
|
156
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
157
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
158
|
+
}, z.core.$strict>;
|
|
159
|
+
/**
|
|
160
|
+
* Auth provider mapping for tool metadata.
|
|
161
|
+
* Used in @Tool({ authProviders: [...] }) decorator.
|
|
162
|
+
*/
|
|
163
|
+
export interface AuthProviderMapping {
|
|
164
|
+
/** Provider name */
|
|
165
|
+
name: string;
|
|
166
|
+
/** Whether credential is required (default: true) */
|
|
167
|
+
required?: boolean;
|
|
168
|
+
/** Required scopes for OAuth providers */
|
|
169
|
+
scopes?: string[];
|
|
170
|
+
/** Alias to use when injecting (for multiple providers) */
|
|
171
|
+
alias?: string;
|
|
172
|
+
}
|
|
173
|
+
export declare const authProviderMappingSchema: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
174
|
+
name: z.ZodString;
|
|
175
|
+
required: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
176
|
+
scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
177
|
+
alias: z.ZodOptional<z.ZodString>;
|
|
178
|
+
}, z.core.$strict>]>;
|
|
179
|
+
/**
|
|
180
|
+
* Internal cache entry structure
|
|
181
|
+
*/
|
|
182
|
+
export interface CredentialCacheEntry<T extends Credential = Credential> {
|
|
183
|
+
/** The resolved credential */
|
|
184
|
+
resolved: ResolvedCredential<T>;
|
|
185
|
+
/** Cache insertion timestamp */
|
|
186
|
+
cachedAt: number;
|
|
187
|
+
/** Cache TTL in ms (0 = no TTL) */
|
|
188
|
+
ttl: number;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Vault storage key components
|
|
192
|
+
*/
|
|
193
|
+
export interface VaultStorageKey {
|
|
194
|
+
/** Credential scope */
|
|
195
|
+
scope: CredentialScope;
|
|
196
|
+
/** Provider name */
|
|
197
|
+
providerId: string;
|
|
198
|
+
/** Session ID (for session scope) */
|
|
199
|
+
sessionId?: string;
|
|
200
|
+
/** User ID (for user scope) */
|
|
201
|
+
userId?: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Configuration options for AuthProviders vault
|
|
205
|
+
*/
|
|
206
|
+
export interface AuthProvidersVaultOptions {
|
|
207
|
+
/** Enable AuthProvidersVault (default: true if any providers registered) */
|
|
208
|
+
enabled?: boolean;
|
|
209
|
+
/** Use shared storage with AuthorizationVault (default: true) */
|
|
210
|
+
useSharedStorage?: boolean;
|
|
211
|
+
/** Custom namespace for credential storage (default: 'authproviders:') */
|
|
212
|
+
namespace?: string;
|
|
213
|
+
/** Default TTL for cached credentials in ms (default: 3600000 = 1 hour) */
|
|
214
|
+
defaultCacheTtl?: number;
|
|
215
|
+
/** Maximum credentials per session (default: 100) */
|
|
216
|
+
maxCredentialsPerSession?: number;
|
|
217
|
+
/** Credential providers to register */
|
|
218
|
+
providers?: CredentialProviderConfig[];
|
|
219
|
+
}
|
|
220
|
+
export declare const authProvidersVaultOptionsSchema: z.ZodObject<{
|
|
221
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
222
|
+
useSharedStorage: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
223
|
+
namespace: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
224
|
+
defaultCacheTtl: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
225
|
+
maxCredentialsPerSession: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
226
|
+
providers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
227
|
+
name: z.ZodString;
|
|
228
|
+
description: z.ZodOptional<z.ZodString>;
|
|
229
|
+
scope: z.ZodEnum<{
|
|
230
|
+
user: "user";
|
|
231
|
+
global: "global";
|
|
232
|
+
session: "session";
|
|
233
|
+
}>;
|
|
234
|
+
loading: z.ZodEnum<{
|
|
235
|
+
lazy: "lazy";
|
|
236
|
+
eager: "eager";
|
|
237
|
+
}>;
|
|
238
|
+
cacheTtl: z.ZodOptional<z.ZodNumber>;
|
|
239
|
+
factory: z.ZodAny;
|
|
240
|
+
refresh: z.ZodOptional<z.ZodAny>;
|
|
241
|
+
toHeaders: z.ZodOptional<z.ZodAny>;
|
|
242
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
243
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
244
|
+
}, z.core.$strict>>>;
|
|
245
|
+
}, z.core.$strict>;
|
|
246
|
+
/**
|
|
247
|
+
* Credential event types
|
|
248
|
+
*/
|
|
249
|
+
export type CredentialEventType = 'acquired' | 'refreshed' | 'invalidated' | 'expired' | 'error';
|
|
250
|
+
/**
|
|
251
|
+
* Credential event payload
|
|
252
|
+
*/
|
|
253
|
+
export interface CredentialEvent {
|
|
254
|
+
type: CredentialEventType;
|
|
255
|
+
providerId: string;
|
|
256
|
+
scope: CredentialScope;
|
|
257
|
+
sessionId?: string;
|
|
258
|
+
userId?: string;
|
|
259
|
+
timestamp: number;
|
|
260
|
+
error?: Error;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=auth-providers.types.d.ts.map
|
|
@@ -0,0 +1 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O,CAAC;IAElB,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,2EAA2E;IAC3E,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,qDAAqD;IACrD,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC,uCAAuC;IACvC,SAAS,CAAC,EAAE,wBAAwB,EAAE,CAAC;CACxC;AAED,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;kBASjC,CAAC;AAMZ;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,GAAG,WAAW,GAAG,aAAa,GAAG,SAAS,GAAG,OAAO,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,eAAe,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CredentialCache - Session-scoped in-memory cache for credentials
|
|
3
|
+
*
|
|
4
|
+
* Provides fast access to recently used credentials with TTL-based expiration.
|
|
5
|
+
* Each cache instance is scoped to a session/request context.
|
|
6
|
+
*/
|
|
7
|
+
import type { Credential } from '../session';
|
|
8
|
+
import type { ResolvedCredential, CredentialScope } from './auth-providers.types';
|
|
9
|
+
/**
|
|
10
|
+
* Cache statistics for monitoring
|
|
11
|
+
*/
|
|
12
|
+
export interface CacheStats {
|
|
13
|
+
hits: number;
|
|
14
|
+
misses: number;
|
|
15
|
+
evictions: number;
|
|
16
|
+
size: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* CredentialCache - In-memory credential cache with TTL support
|
|
20
|
+
*/
|
|
21
|
+
export declare class CredentialCache {
|
|
22
|
+
private readonly cache;
|
|
23
|
+
private readonly maxSize;
|
|
24
|
+
private stats;
|
|
25
|
+
constructor(maxSize?: number);
|
|
26
|
+
/**
|
|
27
|
+
* Get a cached credential
|
|
28
|
+
*
|
|
29
|
+
* @param providerId - Provider name
|
|
30
|
+
* @returns Resolved credential or undefined if not cached or expired
|
|
31
|
+
*/
|
|
32
|
+
get<T extends Credential = Credential>(providerId: string): ResolvedCredential<T> | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Cache a resolved credential
|
|
35
|
+
*
|
|
36
|
+
* @param providerId - Provider name
|
|
37
|
+
* @param resolved - Resolved credential to cache
|
|
38
|
+
* @param ttl - TTL in milliseconds (0 = no TTL, rely on credential expiry)
|
|
39
|
+
*/
|
|
40
|
+
set<T extends Credential = Credential>(providerId: string, resolved: ResolvedCredential<T>, ttl?: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a credential is cached and valid
|
|
43
|
+
*
|
|
44
|
+
* @param providerId - Provider name
|
|
45
|
+
* @returns true if cached and not expired
|
|
46
|
+
*/
|
|
47
|
+
has(providerId: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Invalidate (remove) a cached credential
|
|
50
|
+
*
|
|
51
|
+
* @param providerId - Provider name to invalidate
|
|
52
|
+
* @returns true if credential was removed
|
|
53
|
+
*/
|
|
54
|
+
invalidate(providerId: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Invalidate all cached credentials
|
|
57
|
+
*/
|
|
58
|
+
invalidateAll(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Invalidate credentials by scope
|
|
61
|
+
*
|
|
62
|
+
* @param scope - Credential scope to invalidate
|
|
63
|
+
*/
|
|
64
|
+
invalidateByScope(scope: CredentialScope): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get all cached provider IDs
|
|
67
|
+
*/
|
|
68
|
+
keys(): string[];
|
|
69
|
+
/**
|
|
70
|
+
* Get cache size
|
|
71
|
+
*/
|
|
72
|
+
get size(): number;
|
|
73
|
+
/**
|
|
74
|
+
* Get cache statistics
|
|
75
|
+
*/
|
|
76
|
+
getStats(): CacheStats;
|
|
77
|
+
/**
|
|
78
|
+
* Reset cache statistics
|
|
79
|
+
*/
|
|
80
|
+
resetStats(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Clean up expired entries
|
|
83
|
+
*/
|
|
84
|
+
cleanup(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Check if entry is expired based on TTL
|
|
87
|
+
*/
|
|
88
|
+
private isExpired;
|
|
89
|
+
/**
|
|
90
|
+
* Check if entry is expired at a given timestamp
|
|
91
|
+
*/
|
|
92
|
+
private isExpiredAt;
|
|
93
|
+
/**
|
|
94
|
+
* Evict the oldest entry from cache
|
|
95
|
+
*/
|
|
96
|
+
private evictOldest;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=credential-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-cache.d.ts","sourceRoot":"","sources":["../../src/vault/credential-cache.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAwB,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAExG;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2C;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,KAAK,CAA6D;gBAE9D,OAAO,SAAM;IAIzB;;;;;OAKG;IACH,GAAG,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,UAAU,EAAE,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,GAAG,SAAS;IA8B7F;;;;;;OAMG;IACH,GAAG,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,SAAI,GAAG,IAAI;IAgB1G;;;;;OAKG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAchC;;;;;OAKG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAQvC;;OAEG;IACH,aAAa,IAAI,IAAI;IAKrB;;;;OAIG;IACH,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAS/C;;OAEG;IACH,IAAI,IAAI,MAAM,EAAE;IAMhB;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,QAAQ,IAAI,UAAU;IAItB;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,OAAO,IAAI,IAAI;IAWf;;OAEG;IACH,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,OAAO,CAAC,WAAW;IAmBnB;;OAEG;IACH,OAAO,CAAC,WAAW;CAiBpB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential Helpers
|
|
3
|
+
*
|
|
4
|
+
* Shared utilities for credential handling.
|
|
5
|
+
*/
|
|
6
|
+
import type { Credential } from '../session';
|
|
7
|
+
/**
|
|
8
|
+
* Extract expiry time from a credential.
|
|
9
|
+
*
|
|
10
|
+
* @param credential - The credential to extract expiry from
|
|
11
|
+
* @returns Expiry timestamp in epoch ms, or undefined if no expiry
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractCredentialExpiry(credential: Credential): number | undefined;
|
|
14
|
+
//# sourceMappingURL=credential-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-helpers.d.ts","sourceRoot":"","sources":["../../src/vault/credential-helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAUlF"}
|
package/vault/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vault Module
|
|
3
|
+
*
|
|
4
|
+
* Types and utilities for credential management and auth provider integration.
|
|
5
|
+
*/
|
|
6
|
+
export type { CredentialScope, LoadingStrategy, GetCredentialOptions, ResolvedCredential, CredentialFactoryContext, CredentialFactory, CredentialRefreshFn, CredentialHeadersFn, CredentialProviderConfig, AuthProviderMapping, CredentialCacheEntry, VaultStorageKey, AuthProvidersVaultOptions, CredentialEventType, CredentialEvent, } from './auth-providers.types';
|
|
7
|
+
export { credentialScopeSchema, loadingStrategySchema, getCredentialOptionsSchema, credentialProviderConfigSchema, authProviderMappingSchema, authProvidersVaultOptionsSchema, } from './auth-providers.types';
|
|
8
|
+
export { extractCredentialExpiry } from './credential-helpers';
|
|
9
|
+
export { CredentialCache, type CacheStats } from './credential-cache';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vault/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,0BAA0B,EAC1B,8BAA8B,EAC9B,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,EAAE,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|