@prmichaelsen/mcp-auth 0.1.1 → 0.1.3

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 (50) hide show
  1. package/README.md +5 -0
  2. package/dist/auth/base-provider.d.ts +85 -0
  3. package/dist/auth/base-provider.d.ts.map +1 -0
  4. package/dist/auth/index.d.ts +7 -0
  5. package/dist/auth/index.d.ts.map +1 -0
  6. package/dist/auth/providers/api-token-resolver.d.ts +110 -0
  7. package/dist/auth/providers/api-token-resolver.d.ts.map +1 -0
  8. package/dist/auth/providers/env-provider.d.ts +65 -0
  9. package/dist/auth/providers/env-provider.d.ts.map +1 -0
  10. package/dist/auth/providers/index.d.ts +9 -0
  11. package/dist/auth/providers/index.d.ts.map +1 -0
  12. package/dist/auth/providers/jwt-provider.d.ts +133 -0
  13. package/dist/auth/providers/jwt-provider.d.ts.map +1 -0
  14. package/dist/auth/providers/jwt-token-resolver.d.ts +84 -0
  15. package/dist/auth/providers/jwt-token-resolver.d.ts.map +1 -0
  16. package/dist/auth/providers/simple-resolver.d.ts +109 -0
  17. package/dist/auth/providers/simple-resolver.d.ts.map +1 -0
  18. package/dist/auth/types.d.ts +215 -0
  19. package/dist/auth/types.d.ts.map +1 -0
  20. package/dist/index.d.ts +57 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/server/config.d.ts +90 -0
  23. package/dist/server/config.d.ts.map +1 -0
  24. package/dist/server/decorators.d.ts +136 -0
  25. package/dist/server/decorators.d.ts.map +1 -0
  26. package/dist/server/index.d.ts +10 -0
  27. package/dist/server/index.d.ts.map +1 -0
  28. package/dist/server/mcp-server.d.ts +122 -0
  29. package/dist/server/mcp-server.d.ts.map +1 -0
  30. package/dist/server/tool.d.ts +120 -0
  31. package/dist/server/tool.d.ts.map +1 -0
  32. package/dist/types.d.ts +202 -0
  33. package/dist/types.d.ts.map +1 -0
  34. package/dist/utils/errors.d.ts +116 -0
  35. package/dist/utils/errors.d.ts.map +1 -0
  36. package/dist/utils/index.d.ts +7 -0
  37. package/dist/utils/index.d.ts.map +1 -0
  38. package/dist/utils/logger.d.ts +94 -0
  39. package/dist/utils/logger.d.ts.map +1 -0
  40. package/dist/utils/validation.d.ts +70 -0
  41. package/dist/utils/validation.d.ts.map +1 -0
  42. package/dist/wrapper/config.d.ts +158 -0
  43. package/dist/wrapper/config.d.ts.map +1 -0
  44. package/dist/wrapper/index.d.ts +36 -0
  45. package/dist/wrapper/index.d.ts.map +1 -0
  46. package/dist/wrapper/server-wrapper.d.ts +103 -0
  47. package/dist/wrapper/server-wrapper.d.ts.map +1 -0
  48. package/dist/wrapper/server-wrapper.js +12 -0
  49. package/dist/wrapper/server-wrapper.js.map +2 -2
  50. package/package.json +1 -1
package/README.md CHANGED
@@ -230,6 +230,11 @@ transport: {
230
230
  }
231
231
  ```
232
232
 
233
+ **Endpoints created:**
234
+ - `GET /mcp` - Server info and available endpoints
235
+ - `POST /mcp/message` - MCP protocol messages (requires JWT)
236
+ - `GET /mcp/health` - Health check endpoint
237
+
233
238
  ### HTTP (Remote)
234
239
 
235
240
  ```typescript
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Base authentication provider implementation
3
+ *
4
+ * Provides common functionality for authentication providers.
5
+ */
6
+ import type { AuthProvider, AuthProviderConfig } from './types.js';
7
+ import type { RequestContext, AuthResult } from '../types.js';
8
+ import { type Logger } from '../utils/logger.js';
9
+ /**
10
+ * Abstract base class for authentication providers
11
+ *
12
+ * Provides common functionality like caching, logging, and error handling.
13
+ * Extend this class to implement custom authentication logic.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * class MyAuthProvider extends BaseAuthProvider {
18
+ * protected async doAuthenticate(context: RequestContext): Promise<AuthResult> {
19
+ * // Your authentication logic here
20
+ * return { authenticated: true, userId: 'user-123' };
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ export declare abstract class BaseAuthProvider implements AuthProvider {
26
+ protected config: AuthProviderConfig;
27
+ protected logger: Logger;
28
+ private authCache;
29
+ constructor(config?: AuthProviderConfig);
30
+ /**
31
+ * Authenticate a request
32
+ * Implements caching if enabled
33
+ */
34
+ authenticate(context: RequestContext): Promise<AuthResult>;
35
+ /**
36
+ * Abstract method to implement authentication logic
37
+ * Override this in your provider implementation
38
+ */
39
+ protected abstract doAuthenticate(context: RequestContext): Promise<AuthResult>;
40
+ /**
41
+ * Generate cache key from request context
42
+ * Override this to customize caching behavior
43
+ */
44
+ protected getCacheKey(context: RequestContext): string | null;
45
+ /**
46
+ * Extract authorization header from context
47
+ */
48
+ protected getAuthorizationHeader(context: RequestContext): string | null;
49
+ /**
50
+ * Extract bearer token from authorization header
51
+ */
52
+ protected extractBearerToken(context: RequestContext): string | null;
53
+ /**
54
+ * Create authentication failure result
55
+ */
56
+ protected createFailureResult(error: string): AuthResult;
57
+ /**
58
+ * Create authentication success result
59
+ */
60
+ protected createSuccessResult(userId: string, metadata?: Record<string, unknown>): AuthResult;
61
+ /**
62
+ * Optional: Initialize the provider
63
+ */
64
+ initialize(): Promise<void>;
65
+ /**
66
+ * Optional: Cleanup resources
67
+ */
68
+ cleanup(): Promise<void>;
69
+ /**
70
+ * Optional: Validate provider configuration
71
+ */
72
+ validate(): Promise<boolean>;
73
+ /**
74
+ * Clear authentication cache
75
+ */
76
+ clearCache(): void;
77
+ /**
78
+ * Get cache statistics
79
+ */
80
+ getCacheStats(): {
81
+ size: number;
82
+ keys: string[];
83
+ };
84
+ }
85
+ //# sourceMappingURL=base-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-provider.d.ts","sourceRoot":"","sources":["../../src/auth/base-provider.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9D,OAAO,EAAgB,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;;;;;;;;;;;;;;GAeG;AACH,8BAAsB,gBAAiB,YAAW,YAAY;IAC5D,SAAS,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACrC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,SAAS,CAAyD;gBAE9D,MAAM,GAAE,kBAAuB;IAgB3C;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IA6DhE;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAE/E;;;OAGG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI;IAS7D;;OAEG;IACH,SAAS,CAAC,sBAAsB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI;IAcxE;;OAEG;IACH,SAAS,CAAC,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI;IAepE;;OAEG;IACH,SAAS,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAOxD;;OAEG;IACH,SAAS,CAAC,mBAAmB,CAC3B,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,UAAU;IAQb;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAOjC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAMlC;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACH,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE;CAMlD"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Authentication module exports
3
+ */
4
+ export type { AuthProvider, ResourceTokenResolver, AuthenticatedContext, AuthProviderConfig, TokenResolverConfig } from './types.js';
5
+ export { BaseAuthProvider } from './base-provider.js';
6
+ export { EnvAuthProvider, type EnvAuthProviderConfig, SimpleTokenResolver, type SimpleTokenResolverConfig, JWTAuthProvider, type JWTAuthProviderConfig, type JWTPayload, JWTTokenResolver, type JWTTokenResolverConfig, APITokenResolver, type APITokenResolverConfig } from './providers/index.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,EAC1B,mBAAmB,EACnB,KAAK,yBAAyB,EAC9B,eAAe,EACf,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,gBAAgB,EAChB,KAAK,sBAAsB,EAC3B,gBAAgB,EAChB,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * API-based token resolver
3
+ *
4
+ * Resolves tokens by calling the tenant manager's API.
5
+ * Alternative to JWT-embedded tokens for better separation.
6
+ */
7
+ import type { ResourceTokenResolver, TokenResolverConfig } from '../types.js';
8
+ /**
9
+ * Configuration for APITokenResolver
10
+ */
11
+ export interface APITokenResolverConfig extends TokenResolverConfig {
12
+ /**
13
+ * Tenant manager API base URL
14
+ * @example 'https://tenant-manager.example.com'
15
+ */
16
+ tenantManagerUrl: string;
17
+ /**
18
+ * Service token for authenticating MCP server → tenant manager requests
19
+ * This is a separate token from user JWTs
20
+ */
21
+ serviceToken: string;
22
+ /**
23
+ * API endpoint path template
24
+ * @default '/api/credentials/:userId/:resourceType'
25
+ *
26
+ * Variables:
27
+ * - :userId - Will be replaced with actual user ID
28
+ * - :resourceType - Will be replaced with resource type
29
+ */
30
+ endpointPath?: string;
31
+ /**
32
+ * Request timeout in milliseconds
33
+ * @default 5000
34
+ */
35
+ timeoutMs?: number;
36
+ /**
37
+ * Whether to throw error if token is not found
38
+ * @default true
39
+ */
40
+ throwOnMissing?: boolean;
41
+ /**
42
+ * Whether to validate token format
43
+ * @default true
44
+ */
45
+ validateToken?: boolean;
46
+ /**
47
+ * Custom headers to include in API requests
48
+ */
49
+ customHeaders?: Record<string, string>;
50
+ }
51
+ /**
52
+ * API token resolver
53
+ *
54
+ * Resolves tokens by calling the tenant manager's API endpoint.
55
+ * This approach provides better separation between MCP server and tenant manager.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const resolver = new APITokenResolver({
60
+ * tenantManagerUrl: 'https://tenant-manager.example.com',
61
+ * serviceToken: process.env.SERVICE_TOKEN
62
+ * });
63
+ *
64
+ * // Calls: GET https://tenant-manager.example.com/api/credentials/user-123/instagram
65
+ * // Headers: { Authorization: Bearer <service-token> }
66
+ * // Returns: { accessToken: "IGQVJXabc..." }
67
+ * ```
68
+ */
69
+ export declare class APITokenResolver implements ResourceTokenResolver {
70
+ private config;
71
+ private logger;
72
+ private tokenCache;
73
+ constructor(config: APITokenResolverConfig);
74
+ /**
75
+ * Resolve token by calling tenant manager API
76
+ */
77
+ resolveToken(userId: string, resourceType: string): Promise<string | null>;
78
+ /**
79
+ * Build API URL from template
80
+ */
81
+ private buildUrl;
82
+ /**
83
+ * Refresh token (calls API again)
84
+ */
85
+ refreshToken(userId: string, resourceType: string): Promise<string | null>;
86
+ /**
87
+ * Validate token (basic check)
88
+ */
89
+ validateToken(token: string, resourceType: string): Promise<boolean>;
90
+ /**
91
+ * Initialize resolver
92
+ */
93
+ initialize(): Promise<void>;
94
+ /**
95
+ * Cleanup resources
96
+ */
97
+ cleanup(): Promise<void>;
98
+ /**
99
+ * Clear token cache
100
+ */
101
+ clearCache(): void;
102
+ /**
103
+ * Get cache statistics
104
+ */
105
+ getCacheStats(): {
106
+ size: number;
107
+ keys: string[];
108
+ };
109
+ }
110
+ //# sourceMappingURL=api-token-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-token-resolver.d.ts","sourceRoot":"","sources":["../../../src/auth/providers/api-token-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAK9E;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAiB,YAAW,qBAAqB;IAC5D,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAoD;gBAE1D,MAAM,EAAE,sBAAsB;IAyB1C;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAqJhF;;OAEG;IACH,OAAO,CAAC,QAAQ;IAQhB;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUhF;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAa1E;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBjC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACH,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE;CAMlD"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Environment variable authentication provider
3
+ *
4
+ * Simple provider for single-user scenarios that reads credentials from environment variables.
5
+ * Useful for local development and stdio mode.
6
+ */
7
+ import { BaseAuthProvider } from '../base-provider.js';
8
+ import type { AuthProviderConfig } from '../types.js';
9
+ import type { RequestContext, AuthResult } from '../../types.js';
10
+ /**
11
+ * Configuration for EnvAuthProvider
12
+ */
13
+ export interface EnvAuthProviderConfig extends AuthProviderConfig {
14
+ /**
15
+ * Environment variable name containing the user ID
16
+ * @default 'MCP_USER_ID'
17
+ */
18
+ userIdEnvVar?: string;
19
+ /**
20
+ * Default user ID if environment variable is not set
21
+ * @default 'default-user'
22
+ */
23
+ defaultUserId?: string;
24
+ /**
25
+ * Whether to require user ID environment variable
26
+ * @default false
27
+ */
28
+ requireUserId?: boolean;
29
+ }
30
+ /**
31
+ * Environment variable authentication provider
32
+ *
33
+ * This provider is designed for single-user scenarios where authentication
34
+ * is not required (e.g., local development, stdio mode).
35
+ *
36
+ * It reads the user ID from an environment variable or uses a default value.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const provider = new EnvAuthProvider({
41
+ * userIdEnvVar: 'MY_USER_ID',
42
+ * defaultUserId: 'local-user'
43
+ * });
44
+ *
45
+ * // Or with defaults
46
+ * const provider = new EnvAuthProvider();
47
+ * ```
48
+ */
49
+ export declare class EnvAuthProvider extends BaseAuthProvider {
50
+ private envConfig;
51
+ constructor(config?: EnvAuthProviderConfig);
52
+ /**
53
+ * Authenticate request by reading user ID from environment
54
+ */
55
+ protected doAuthenticate(context: RequestContext): Promise<AuthResult>;
56
+ /**
57
+ * Validate provider configuration
58
+ */
59
+ validate(): Promise<boolean>;
60
+ /**
61
+ * Get current user ID from environment
62
+ */
63
+ getUserId(): string;
64
+ }
65
+ //# sourceMappingURL=env-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-provider.d.ts","sourceRoot":"","sources":["../../../src/auth/providers/env-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD,OAAO,CAAC,SAAS,CAAkC;gBAEvC,MAAM,GAAE,qBAA0B;IAc9C;;OAEG;cACa,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAqC5E;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAclC;;OAEG;IACH,SAAS,IAAI,MAAM;CAGpB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Authentication providers module exports
3
+ */
4
+ export { EnvAuthProvider, type EnvAuthProviderConfig } from './env-provider.js';
5
+ export { SimpleTokenResolver, type SimpleTokenResolverConfig } from './simple-resolver.js';
6
+ export { JWTAuthProvider, type JWTAuthProviderConfig, type JWTPayload } from './jwt-provider.js';
7
+ export { JWTTokenResolver, type JWTTokenResolverConfig } from './jwt-token-resolver.js';
8
+ export { APITokenResolver, type APITokenResolverConfig } from './api-token-resolver.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,EAC3B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,mBAAmB,EACnB,KAAK,yBAAyB,EAC/B,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,gBAAgB,EAChB,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,gBAAgB,EAChB,KAAK,sBAAsB,EAC5B,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * JWT authentication provider
3
+ *
4
+ * Reference implementation for JWT-based authentication.
5
+ * Validates JWT tokens and optionally extracts embedded resource tokens.
6
+ */
7
+ import { BaseAuthProvider } from '../base-provider.js';
8
+ import type { AuthProviderConfig } from '../types.js';
9
+ import type { RequestContext, AuthResult } from '../../types.js';
10
+ /**
11
+ * JWT payload structure
12
+ */
13
+ export interface JWTPayload {
14
+ /**
15
+ * User ID (standard JWT claim: 'sub' or custom 'userId')
16
+ */
17
+ sub?: string;
18
+ userId?: string;
19
+ /**
20
+ * Optional: Embedded resource tokens
21
+ * { instagram: "token1", github: "token2" }
22
+ */
23
+ tokens?: Record<string, string>;
24
+ /**
25
+ * Expiration time (standard JWT claim)
26
+ */
27
+ exp?: number;
28
+ /**
29
+ * Issued at (standard JWT claim)
30
+ */
31
+ iat?: number;
32
+ /**
33
+ * Additional custom claims
34
+ */
35
+ [key: string]: any;
36
+ }
37
+ /**
38
+ * Configuration for JWTAuthProvider
39
+ */
40
+ export interface JWTAuthProviderConfig extends AuthProviderConfig {
41
+ /**
42
+ * JWT secret for verification
43
+ */
44
+ jwtSecret: string;
45
+ /**
46
+ * JWT algorithm
47
+ * @default 'HS256'
48
+ */
49
+ algorithm?: string;
50
+ /**
51
+ * Whether to extract embedded tokens from JWT
52
+ * If true, tokens will be cached for JWTTokenResolver
53
+ * @default true
54
+ */
55
+ extractTokens?: boolean;
56
+ /**
57
+ * Custom user ID claim name
58
+ * @default 'sub' (falls back to 'userId')
59
+ */
60
+ userIdClaim?: string;
61
+ /**
62
+ * Custom tokens claim name
63
+ * @default 'tokens'
64
+ */
65
+ tokensClaim?: string;
66
+ /**
67
+ * Whether to validate token expiration
68
+ * @default true
69
+ */
70
+ validateExpiration?: boolean;
71
+ /**
72
+ * Clock tolerance in seconds for exp/nbf claims
73
+ * @default 0
74
+ */
75
+ clockTolerance?: number;
76
+ }
77
+ /**
78
+ * JWT authentication provider
79
+ *
80
+ * Validates JWT tokens issued by the tenant manager.
81
+ * Optionally extracts embedded resource tokens from the JWT payload.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // Basic usage
86
+ * const provider = new JWTAuthProvider({
87
+ * jwtSecret: process.env.JWT_SECRET
88
+ * });
89
+ *
90
+ * // With token extraction
91
+ * const provider = new JWTAuthProvider({
92
+ * jwtSecret: process.env.JWT_SECRET,
93
+ * extractTokens: true
94
+ * });
95
+ * ```
96
+ */
97
+ export declare class JWTAuthProvider extends BaseAuthProvider {
98
+ private jwtConfig;
99
+ /**
100
+ * Token cache for extracted tokens
101
+ * Maps userId → resourceType → token
102
+ */
103
+ readonly tokenCache: Map<string, Map<string, string>>;
104
+ constructor(config: JWTAuthProviderConfig);
105
+ /**
106
+ * Authenticate request by validating JWT
107
+ */
108
+ protected doAuthenticate(context: RequestContext): Promise<AuthResult>;
109
+ /**
110
+ * Validate provider configuration
111
+ */
112
+ validate(): Promise<boolean>;
113
+ /**
114
+ * Get cached token for a user and resource
115
+ */
116
+ getCachedToken(userId: string, resourceType: string): string | null;
117
+ /**
118
+ * Clear token cache
119
+ */
120
+ clearTokenCache(): void;
121
+ /**
122
+ * Get token cache statistics
123
+ */
124
+ getTokenCacheStats(): {
125
+ userCount: number;
126
+ totalTokens: number;
127
+ users: Array<{
128
+ userId: string;
129
+ resourceTypes: string[];
130
+ }>;
131
+ };
132
+ }
133
+ //# sourceMappingURL=jwt-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-provider.d.ts","sourceRoot":"","sources":["../../../src/auth/providers/jwt-provider.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,eAAgB,SAAQ,gBAAgB;IACnD,OAAO,CAAC,SAAS,CAAkC;IAEnD;;;OAGG;IACH,SAAgB,UAAU,mCAA0C;gBAExD,MAAM,EAAE,qBAAqB;IAsBzC;;OAEG;cACa,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IA8E5E;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAkBlC;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAInE;;OAEG;IACH,eAAe,IAAI,IAAI;IAKvB;;OAEG;IACH,kBAAkB,IAAI;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,EAAE,KAAK,CAAC;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,aAAa,EAAE,MAAM,EAAE,CAAA;SAAE,CAAC,CAAC;KAC3D;CAcF"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * JWT token resolver
3
+ *
4
+ * Resolves tokens that were extracted from JWT by JWTAuthProvider.
5
+ * Works in conjunction with JWTAuthProvider for JWT-embedded token approach.
6
+ */
7
+ import type { ResourceTokenResolver, TokenResolverConfig } from '../types.js';
8
+ import type { JWTAuthProvider } from './jwt-provider.js';
9
+ /**
10
+ * Configuration for JWTTokenResolver
11
+ */
12
+ export interface JWTTokenResolverConfig extends TokenResolverConfig {
13
+ /**
14
+ * JWTAuthProvider instance that extracts tokens
15
+ */
16
+ authProvider: JWTAuthProvider;
17
+ /**
18
+ * Whether to throw error if token is not found
19
+ * @default true
20
+ */
21
+ throwOnMissing?: boolean;
22
+ }
23
+ /**
24
+ * JWT token resolver
25
+ *
26
+ * Resolves tokens that were cached by JWTAuthProvider during authentication.
27
+ * This is used for the JWT-embedded token approach where the JWT contains
28
+ * all resource tokens.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const authProvider = new JWTAuthProvider({
33
+ * jwtSecret: process.env.JWT_SECRET,
34
+ * extractTokens: true
35
+ * });
36
+ *
37
+ * const tokenResolver = new JWTTokenResolver({
38
+ * authProvider
39
+ * });
40
+ *
41
+ * // JWT structure:
42
+ * // {
43
+ * // "userId": "user-123",
44
+ * // "tokens": {
45
+ * // "instagram": "IGQVJXabc...",
46
+ * // "github": "ghp_abc123..."
47
+ * // }
48
+ * // }
49
+ * ```
50
+ */
51
+ export declare class JWTTokenResolver implements ResourceTokenResolver {
52
+ private config;
53
+ private logger;
54
+ constructor(config: JWTTokenResolverConfig);
55
+ /**
56
+ * Resolve token from JWT auth provider's cache
57
+ */
58
+ resolveToken(userId: string, resourceType: string): Promise<string | null>;
59
+ /**
60
+ * Refresh token (not supported for JWT-embedded tokens)
61
+ */
62
+ refreshToken(userId: string, resourceType: string): Promise<string | null>;
63
+ /**
64
+ * Validate token (checks if token exists in cache)
65
+ */
66
+ validateToken(token: string, resourceType: string): Promise<boolean>;
67
+ /**
68
+ * Initialize resolver
69
+ */
70
+ initialize(): Promise<void>;
71
+ /**
72
+ * Cleanup resources
73
+ */
74
+ cleanup(): Promise<void>;
75
+ /**
76
+ * Get available resource types for a user
77
+ */
78
+ getAvailableResources(userId: string): string[];
79
+ /**
80
+ * Check if token is available for a user and resource
81
+ */
82
+ hasToken(userId: string, resourceType: string): boolean;
83
+ }
84
+ //# sourceMappingURL=jwt-token-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-token-resolver.d.ts","sourceRoot":"","sources":["../../../src/auth/providers/jwt-token-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIzD;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE;;OAEG;IACH,YAAY,EAAE,eAAe,CAAC;IAE9B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,gBAAiB,YAAW,qBAAqB;IAC5D,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,sBAAsB;IAgB1C;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgChF;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUhF;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK1E;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B;;OAEG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAK/C;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO;CAGxD"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Simple token resolver for single-user scenarios
3
+ *
4
+ * Resolves tokens from environment variables. Useful for local development
5
+ * and single-user deployments where all users share the same token.
6
+ */
7
+ import type { ResourceTokenResolver, TokenResolverConfig } from '../types.js';
8
+ /**
9
+ * Configuration for SimpleTokenResolver
10
+ */
11
+ export interface SimpleTokenResolverConfig extends TokenResolverConfig {
12
+ /**
13
+ * Environment variable name containing the access token
14
+ * @default 'ACCESS_TOKEN'
15
+ */
16
+ tokenEnvVar?: string;
17
+ /**
18
+ * Optional: Map of resource types to environment variable names
19
+ * Overrides tokenEnvVar for specific resource types
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * {
24
+ * instagram: 'INSTAGRAM_ACCESS_TOKEN',
25
+ * github: 'GITHUB_ACCESS_TOKEN'
26
+ * }
27
+ * ```
28
+ */
29
+ resourceTokenEnvVars?: Record<string, string>;
30
+ /**
31
+ * Whether to throw error if token is not found
32
+ * @default true
33
+ */
34
+ throwOnMissing?: boolean;
35
+ /**
36
+ * Whether to validate token format
37
+ * @default true
38
+ */
39
+ validateToken?: boolean;
40
+ }
41
+ /**
42
+ * Simple token resolver that reads tokens from environment variables
43
+ *
44
+ * This resolver is designed for single-user scenarios where authentication
45
+ * is handled externally or not required. It reads resource-specific tokens
46
+ * from environment variables.
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Single token for all resources
51
+ * const resolver = new SimpleTokenResolver({
52
+ * tokenEnvVar: 'API_TOKEN'
53
+ * });
54
+ *
55
+ * // Different tokens per resource
56
+ * const resolver = new SimpleTokenResolver({
57
+ * resourceTokenEnvVars: {
58
+ * instagram: 'INSTAGRAM_ACCESS_TOKEN',
59
+ * github: 'GITHUB_ACCESS_TOKEN'
60
+ * }
61
+ * });
62
+ * ```
63
+ */
64
+ export declare class SimpleTokenResolver implements ResourceTokenResolver {
65
+ private config;
66
+ private logger;
67
+ private tokenCache;
68
+ constructor(config?: SimpleTokenResolverConfig);
69
+ /**
70
+ * Resolve access token for a user and resource type
71
+ */
72
+ resolveToken(userId: string, resourceType: string): Promise<string | null>;
73
+ /**
74
+ * Optional: Refresh token (not supported for env-based tokens)
75
+ */
76
+ refreshToken(userId: string, resourceType: string): Promise<string | null>;
77
+ /**
78
+ * Optional: Validate token (checks if env var is set)
79
+ */
80
+ validateToken(token: string, resourceType: string): Promise<boolean>;
81
+ /**
82
+ * Optional: Initialize resolver
83
+ */
84
+ initialize(): Promise<void>;
85
+ /**
86
+ * Optional: Cleanup resources
87
+ */
88
+ cleanup(): Promise<void>;
89
+ /**
90
+ * Clear token cache
91
+ */
92
+ clearCache(): void;
93
+ /**
94
+ * Get cache statistics
95
+ */
96
+ getCacheStats(): {
97
+ size: number;
98
+ keys: string[];
99
+ };
100
+ /**
101
+ * Check if token is available for a resource type
102
+ */
103
+ hasToken(resourceType: string): boolean;
104
+ /**
105
+ * Get all available resource types
106
+ */
107
+ getAvailableResources(): string[];
108
+ }
109
+ //# sourceMappingURL=simple-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-resolver.d.ts","sourceRoot":"","sources":["../../../src/auth/providers/simple-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAK9E;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;;;;;OAWG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE9C;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,mBAAoB,YAAW,qBAAqB;IAC/D,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAoD;gBAE1D,MAAM,GAAE,yBAA8B;IAelD;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA0FhF;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUhF;;OAEG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAa1E;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBjC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACH,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE;IAOjD;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO;IAOvC;;OAEG;IACH,qBAAqB,IAAI,MAAM,EAAE;CAiBlC"}