nitrostack 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +227 -0
- package/CONTRIBUTING.md +182 -0
- package/LICENSE +201 -0
- package/LICENSE_URLS_UPDATE_COMPLETE.md +388 -0
- package/NOTICE +153 -0
- package/README.md +571 -0
- package/dist/auth/api-key.d.ts +118 -0
- package/dist/auth/api-key.d.ts.map +1 -0
- package/dist/auth/api-key.js +168 -0
- package/dist/auth/api-key.js.map +1 -0
- package/dist/auth/client.d.ts +151 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +330 -0
- package/dist/auth/client.js.map +1 -0
- package/dist/auth/index.d.ts +30 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +43 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/middleware.d.ts +95 -0
- package/dist/auth/middleware.d.ts.map +1 -0
- package/dist/auth/middleware.js +260 -0
- package/dist/auth/middleware.js.map +1 -0
- package/dist/auth/pkce.d.ts +53 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +105 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/quick-setup.d.ts +94 -0
- package/dist/auth/quick-setup.d.ts.map +1 -0
- package/dist/auth/quick-setup.js +210 -0
- package/dist/auth/quick-setup.js.map +1 -0
- package/dist/auth/server-integration.d.ts +97 -0
- package/dist/auth/server-integration.d.ts.map +1 -0
- package/dist/auth/server-integration.js +182 -0
- package/dist/auth/server-integration.js.map +1 -0
- package/dist/auth/server-metadata.d.ts +51 -0
- package/dist/auth/server-metadata.d.ts.map +1 -0
- package/dist/auth/server-metadata.js +106 -0
- package/dist/auth/server-metadata.js.map +1 -0
- package/dist/auth/simple-jwt.d.ts +88 -0
- package/dist/auth/simple-jwt.d.ts.map +1 -0
- package/dist/auth/simple-jwt.js +152 -0
- package/dist/auth/simple-jwt.js.map +1 -0
- package/dist/auth/token-store.d.ts +104 -0
- package/dist/auth/token-store.d.ts.map +1 -0
- package/dist/auth/token-store.js +205 -0
- package/dist/auth/token-store.js.map +1 -0
- package/dist/auth/token-validation.d.ts +47 -0
- package/dist/auth/token-validation.d.ts.map +1 -0
- package/dist/auth/token-validation.js +237 -0
- package/dist/auth/token-validation.js.map +1 -0
- package/dist/auth/types.d.ts +215 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +6 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/cli/commands/build.d.ts +6 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +104 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +7 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +312 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/generate-types.d.ts +8 -0
- package/dist/cli/commands/generate-types.d.ts.map +1 -0
- package/dist/cli/commands/generate-types.js +220 -0
- package/dist/cli/commands/generate-types.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +5 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +365 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/init.d.ts +7 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +365 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/start.d.ts +6 -0
- package/dist/cli/commands/start.d.ts.map +1 -0
- package/dist/cli/commands/start.js +61 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +47 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/mcp-dev-wrapper.d.ts +3 -0
- package/dist/cli/mcp-dev-wrapper.d.ts.map +1 -0
- package/dist/cli/mcp-dev-wrapper.js +116 -0
- package/dist/cli/mcp-dev-wrapper.js.map +1 -0
- package/dist/core/apikey-module.d.ts +69 -0
- package/dist/core/apikey-module.d.ts.map +1 -0
- package/dist/core/apikey-module.js +114 -0
- package/dist/core/apikey-module.js.map +1 -0
- package/dist/core/app-decorator.d.ts +58 -0
- package/dist/core/app-decorator.d.ts.map +1 -0
- package/dist/core/app-decorator.js +261 -0
- package/dist/core/app-decorator.js.map +1 -0
- package/dist/core/builders.d.ts +38 -0
- package/dist/core/builders.d.ts.map +1 -0
- package/dist/core/builders.js +129 -0
- package/dist/core/builders.js.map +1 -0
- package/dist/core/component.d.ts +105 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/component.js +182 -0
- package/dist/core/component.js.map +1 -0
- package/dist/core/config-module.d.ts +55 -0
- package/dist/core/config-module.d.ts.map +1 -0
- package/dist/core/config-module.js +94 -0
- package/dist/core/config-module.js.map +1 -0
- package/dist/core/decorators/cache.decorator.d.ts +61 -0
- package/dist/core/decorators/cache.decorator.d.ts.map +1 -0
- package/dist/core/decorators/cache.decorator.js +115 -0
- package/dist/core/decorators/cache.decorator.js.map +1 -0
- package/dist/core/decorators/health-check.decorator.d.ts +80 -0
- package/dist/core/decorators/health-check.decorator.d.ts.map +1 -0
- package/dist/core/decorators/health-check.decorator.js +153 -0
- package/dist/core/decorators/health-check.decorator.js.map +1 -0
- package/dist/core/decorators/rate-limit.decorator.d.ts +62 -0
- package/dist/core/decorators/rate-limit.decorator.d.ts.map +1 -0
- package/dist/core/decorators/rate-limit.decorator.js +129 -0
- package/dist/core/decorators/rate-limit.decorator.js.map +1 -0
- package/dist/core/decorators.d.ts +151 -0
- package/dist/core/decorators.d.ts.map +1 -0
- package/dist/core/decorators.js +142 -0
- package/dist/core/decorators.js.map +1 -0
- package/dist/core/di/container.d.ts +42 -0
- package/dist/core/di/container.d.ts.map +1 -0
- package/dist/core/di/container.js +76 -0
- package/dist/core/di/container.js.map +1 -0
- package/dist/core/di/injectable.decorator.d.ts +35 -0
- package/dist/core/di/injectable.decorator.d.ts.map +1 -0
- package/dist/core/di/injectable.decorator.js +57 -0
- package/dist/core/di/injectable.decorator.js.map +1 -0
- package/dist/core/errors.d.ts +54 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +87 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/events/event-emitter.d.ts +50 -0
- package/dist/core/events/event-emitter.d.ts.map +1 -0
- package/dist/core/events/event-emitter.js +94 -0
- package/dist/core/events/event-emitter.js.map +1 -0
- package/dist/core/events/event.decorator.d.ts +48 -0
- package/dist/core/events/event.decorator.d.ts.map +1 -0
- package/dist/core/events/event.decorator.js +68 -0
- package/dist/core/events/event.decorator.js.map +1 -0
- package/dist/core/filters/exception-filter.decorator.d.ts +40 -0
- package/dist/core/filters/exception-filter.decorator.d.ts.map +1 -0
- package/dist/core/filters/exception-filter.decorator.js +54 -0
- package/dist/core/filters/exception-filter.decorator.js.map +1 -0
- package/dist/core/filters/exception-filter.interface.d.ts +30 -0
- package/dist/core/filters/exception-filter.interface.d.ts.map +1 -0
- package/dist/core/filters/exception-filter.interface.js +2 -0
- package/dist/core/filters/exception-filter.interface.js.map +1 -0
- package/dist/core/guards/apikey.guard.d.ts +22 -0
- package/dist/core/guards/apikey.guard.d.ts.map +1 -0
- package/dist/core/guards/apikey.guard.js +11 -0
- package/dist/core/guards/apikey.guard.js.map +1 -0
- package/dist/core/guards/guard.interface.d.ts +18 -0
- package/dist/core/guards/guard.interface.d.ts.map +1 -0
- package/dist/core/guards/guard.interface.js +2 -0
- package/dist/core/guards/guard.interface.js.map +1 -0
- package/dist/core/guards/jwt.guard.d.ts +18 -0
- package/dist/core/guards/jwt.guard.d.ts.map +1 -0
- package/dist/core/guards/jwt.guard.js +2 -0
- package/dist/core/guards/jwt.guard.js.map +1 -0
- package/dist/core/guards/oauth.guard.d.ts +35 -0
- package/dist/core/guards/oauth.guard.d.ts.map +1 -0
- package/dist/core/guards/oauth.guard.js +2 -0
- package/dist/core/guards/oauth.guard.js.map +1 -0
- package/dist/core/guards/use-guards.decorator.d.ts +25 -0
- package/dist/core/guards/use-guards.decorator.d.ts.map +1 -0
- package/dist/core/guards/use-guards.decorator.js +32 -0
- package/dist/core/guards/use-guards.decorator.js.map +1 -0
- package/dist/core/health/health-checks.resource.d.ts +14 -0
- package/dist/core/health/health-checks.resource.d.ts.map +1 -0
- package/dist/core/health/health-checks.resource.js +29 -0
- package/dist/core/health/health-checks.resource.js.map +1 -0
- package/dist/core/index.d.ts +55 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +57 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/interceptors/interceptor.decorator.d.ts +37 -0
- package/dist/core/interceptors/interceptor.decorator.d.ts.map +1 -0
- package/dist/core/interceptors/interceptor.decorator.js +51 -0
- package/dist/core/interceptors/interceptor.decorator.js.map +1 -0
- package/dist/core/interceptors/interceptor.interface.d.ts +31 -0
- package/dist/core/interceptors/interceptor.interface.d.ts.map +1 -0
- package/dist/core/interceptors/interceptor.interface.js +2 -0
- package/dist/core/interceptors/interceptor.interface.js.map +1 -0
- package/dist/core/jwt-module.d.ts +51 -0
- package/dist/core/jwt-module.d.ts.map +1 -0
- package/dist/core/jwt-module.js +52 -0
- package/dist/core/jwt-module.js.map +1 -0
- package/dist/core/logger.d.ts +18 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +51 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/middleware/middleware.decorator.d.ts +39 -0
- package/dist/core/middleware/middleware.decorator.d.ts.map +1 -0
- package/dist/core/middleware/middleware.decorator.js +53 -0
- package/dist/core/middleware/middleware.decorator.js.map +1 -0
- package/dist/core/middleware/middleware.interface.d.ts +29 -0
- package/dist/core/middleware/middleware.interface.d.ts.map +1 -0
- package/dist/core/middleware/middleware.interface.js +2 -0
- package/dist/core/middleware/middleware.interface.js.map +1 -0
- package/dist/core/module.d.ts +74 -0
- package/dist/core/module.d.ts.map +1 -0
- package/dist/core/module.js +82 -0
- package/dist/core/module.js.map +1 -0
- package/dist/core/oauth-module.d.ts +144 -0
- package/dist/core/oauth-module.d.ts.map +1 -0
- package/dist/core/oauth-module.js +190 -0
- package/dist/core/oauth-module.js.map +1 -0
- package/dist/core/pipes/pipe.decorator.d.ts +55 -0
- package/dist/core/pipes/pipe.decorator.d.ts.map +1 -0
- package/dist/core/pipes/pipe.decorator.js +85 -0
- package/dist/core/pipes/pipe.decorator.js.map +1 -0
- package/dist/core/pipes/pipe.interface.d.ts +36 -0
- package/dist/core/pipes/pipe.interface.d.ts.map +1 -0
- package/dist/core/pipes/pipe.interface.js +2 -0
- package/dist/core/pipes/pipe.interface.js.map +1 -0
- package/dist/core/prompt.d.ts +37 -0
- package/dist/core/prompt.d.ts.map +1 -0
- package/dist/core/prompt.js +76 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/resource.d.ts +42 -0
- package/dist/core/resource.d.ts.map +1 -0
- package/dist/core/resource.js +90 -0
- package/dist/core/resource.js.map +1 -0
- package/dist/core/server.d.ts +72 -0
- package/dist/core/server.d.ts.map +1 -0
- package/dist/core/server.js +406 -0
- package/dist/core/server.js.map +1 -0
- package/dist/core/tool.d.ts +78 -0
- package/dist/core/tool.d.ts.map +1 -0
- package/dist/core/tool.js +190 -0
- package/dist/core/tool.js.map +1 -0
- package/dist/core/transports/http-server.d.ts +102 -0
- package/dist/core/transports/http-server.d.ts.map +1 -0
- package/dist/core/transports/http-server.js +265 -0
- package/dist/core/transports/http-server.js.map +1 -0
- package/dist/core/types.d.ts +123 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/widgets/widget-examples.resource.d.ts +17 -0
- package/dist/core/widgets/widget-examples.resource.d.ts.map +1 -0
- package/dist/core/widgets/widget-examples.resource.js +28 -0
- package/dist/core/widgets/widget-examples.resource.js.map +1 -0
- package/dist/core/widgets/widget-registry.d.ts +56 -0
- package/dist/core/widgets/widget-registry.d.ts.map +1 -0
- package/dist/core/widgets/widget-registry.js +75 -0
- package/dist/core/widgets/widget-registry.js.map +1 -0
- package/dist/testing/index.d.ts +82 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +164 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/ui-next/index.d.ts +31 -0
- package/dist/ui-next/index.d.ts.map +1 -0
- package/dist/ui-next/index.js +687 -0
- package/dist/ui-next/index.js.map +1 -0
- package/dist/widgets/index.d.ts +9 -0
- package/dist/widgets/index.d.ts.map +1 -0
- package/dist/widgets/index.js +9 -0
- package/dist/widgets/index.js.map +1 -0
- package/dist/widgets/metadata.d.ts +53 -0
- package/dist/widgets/metadata.d.ts.map +1 -0
- package/dist/widgets/metadata.js +29 -0
- package/dist/widgets/metadata.js.map +1 -0
- package/dist/widgets/withToolData.d.ts +19 -0
- package/dist/widgets/withToolData.d.ts.map +1 -0
- package/dist/widgets/withToolData.js +240 -0
- package/dist/widgets/withToolData.js.map +1 -0
- package/jest.config.js +21 -0
- package/package.json +108 -0
- package/templates/typescript-auth/AI_AGENT_CLI_REFERENCE.md +702 -0
- package/templates/typescript-auth/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-auth/README.md +400 -0
- package/templates/typescript-auth/package.json +44 -0
- package/templates/typescript-auth-api-key/AI_AGENT_CLI_REFERENCE.md +701 -0
- package/templates/typescript-auth-api-key/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-auth-api-key/README.md +483 -0
- package/templates/typescript-auth-api-key/package-lock.json +124 -0
- package/templates/typescript-auth-api-key/package.json +29 -0
- package/templates/typescript-oauth/AI_AGENT_CLI_REFERENCE.md +701 -0
- package/templates/typescript-oauth/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-oauth/OAUTH_SETUP.md +406 -0
- package/templates/typescript-oauth/README.md +350 -0
- package/templates/typescript-oauth/package.json +30 -0
- package/templates/typescript-starter/AI_AGENT_CLI_REFERENCE.md +701 -0
- package/templates/typescript-starter/AI_AGENT_SDK_REFERENCE.md +1260 -0
- package/templates/typescript-starter/README.md +312 -0
- package/templates/typescript-starter/package.json +32 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import { SimpleJWTConfig } from './simple-jwt.js';
|
|
3
|
+
import { APIKeyConfig } from './api-key.js';
|
|
4
|
+
import { McpAuthConfig } from './server-integration.js';
|
|
5
|
+
/**
|
|
6
|
+
* Quick Setup Helpers
|
|
7
|
+
*
|
|
8
|
+
* Make it dead simple to add authentication to NitroStack servers
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Setup Simple JWT Authentication (1-liner!)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const server = createServer({...});
|
|
16
|
+
*
|
|
17
|
+
* // That's it! JWT auth enabled
|
|
18
|
+
* setupJWTAuth(server.app, {
|
|
19
|
+
* secret: process.env.JWT_SECRET!,
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* server.start();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function setupJWTAuth(app: Express, config: SimpleJWTConfig, path?: string): void;
|
|
26
|
+
/**
|
|
27
|
+
* Setup API Key Authentication (1-liner!)
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const server = createServer({...});
|
|
32
|
+
*
|
|
33
|
+
* // That's it! API key auth enabled
|
|
34
|
+
* setupAPIKeyAuth(server.app, {
|
|
35
|
+
* keys: [process.env.API_KEY!],
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* server.start();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function setupAPIKeyAuth(app: Express, config: APIKeyConfig, path?: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Setup OAuth 2.1 Authentication (full enterprise setup)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const server = createServer({...});
|
|
48
|
+
*
|
|
49
|
+
* // Full OAuth 2.1 with PKCE
|
|
50
|
+
* setupOAuthAuth(server.app, {
|
|
51
|
+
* resourceUri: 'https://mcp.example.com',
|
|
52
|
+
* authorizationServers: ['https://auth.example.com'],
|
|
53
|
+
* tokenIntrospectionEndpoint: '...',
|
|
54
|
+
* tokenIntrospectionClientId: '...',
|
|
55
|
+
* tokenIntrospectionClientSecret: process.env.INTROSPECTION_SECRET,
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* server.start();
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function setupOAuthAuth(app: Express, config: McpAuthConfig, path?: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Generate test credentials (for development)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const creds = generateTestCredentials();
|
|
68
|
+
* console.log('JWT Secret:', creds.jwtSecret);
|
|
69
|
+
* console.log('API Key:', creds.apiKey);
|
|
70
|
+
* console.log('Sample Token:', creds.sampleToken);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function generateTestCredentials(options?: {
|
|
74
|
+
jwtAudience?: string;
|
|
75
|
+
jwtIssuer?: string;
|
|
76
|
+
apiKeyPrefix?: string;
|
|
77
|
+
}): {
|
|
78
|
+
jwtSecret: string;
|
|
79
|
+
apiKey: string;
|
|
80
|
+
apiKeyHashed: string;
|
|
81
|
+
sampleToken: string;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Print auth setup instructions
|
|
85
|
+
*/
|
|
86
|
+
export declare function printAuthSetupInstructions(type: 'jwt' | 'apikey' | 'oauth'): void;
|
|
87
|
+
/**
|
|
88
|
+
* Validate auth environment variables
|
|
89
|
+
*/
|
|
90
|
+
export declare function validateAuthEnv(type: 'jwt' | 'apikey' | 'oauth'): {
|
|
91
|
+
valid: boolean;
|
|
92
|
+
missing: string[];
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=quick-setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quick-setup.d.ts","sourceRoot":"","sources":["../../src/auth/quick-setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAuB,eAAe,EAAe,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAoB,YAAY,EAA8B,MAAM,cAAc,CAAC;AAC1F,OAAO,EAAuB,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7E;;;;GAIG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,eAAe,EACvB,IAAI,GAAE,MAAe,GACpB,IAAI,CAQN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,YAAY,EACpB,IAAI,GAAE,MAAe,GACpB,IAAI,CAQN;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,aAAa,EACrB,IAAI,GAAE,MAAe,GACpB,IAAI,CASN;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;;;;;EAqBA;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CA8DjF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAmCvG"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { createSimpleJWTAuth, generateJWT } from './simple-jwt.js';
|
|
2
|
+
import { createAPIKeyAuth, generateAPIKey, hashAPIKey } from './api-key.js';
|
|
3
|
+
import { configureServerAuth } from './server-integration.js';
|
|
4
|
+
/**
|
|
5
|
+
* Quick Setup Helpers
|
|
6
|
+
*
|
|
7
|
+
* Make it dead simple to add authentication to NitroStack servers
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Setup Simple JWT Authentication (1-liner!)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const server = createServer({...});
|
|
15
|
+
*
|
|
16
|
+
* // That's it! JWT auth enabled
|
|
17
|
+
* setupJWTAuth(server.app, {
|
|
18
|
+
* secret: process.env.JWT_SECRET!,
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* server.start();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function setupJWTAuth(app, config, path = '/mcp') {
|
|
25
|
+
const middleware = createSimpleJWTAuth(config);
|
|
26
|
+
app.use(path, middleware);
|
|
27
|
+
console.log(`✅ Simple JWT auth enabled on ${path}`);
|
|
28
|
+
console.log(` Audience: ${config.audience || 'any'}`);
|
|
29
|
+
console.log(` Issuer: ${config.issuer || 'any'}`);
|
|
30
|
+
console.log(` Algorithm: ${config.algorithm || 'HS256'}`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Setup API Key Authentication (1-liner!)
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const server = createServer({...});
|
|
38
|
+
*
|
|
39
|
+
* // That's it! API key auth enabled
|
|
40
|
+
* setupAPIKeyAuth(server.app, {
|
|
41
|
+
* keys: [process.env.API_KEY!],
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* server.start();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function setupAPIKeyAuth(app, config, path = '/mcp') {
|
|
48
|
+
const middleware = createAPIKeyAuth(config);
|
|
49
|
+
app.use(path, middleware);
|
|
50
|
+
console.log(`✅ API Key auth enabled on ${path}`);
|
|
51
|
+
console.log(` Header: ${config.headerName || 'X-API-Key'}`);
|
|
52
|
+
console.log(` Keys: ${config.keys.length} configured`);
|
|
53
|
+
console.log(` Query param: ${config.allowQueryParam ? 'enabled' : 'disabled'}`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Setup OAuth 2.1 Authentication (full enterprise setup)
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const server = createServer({...});
|
|
61
|
+
*
|
|
62
|
+
* // Full OAuth 2.1 with PKCE
|
|
63
|
+
* setupOAuthAuth(server.app, {
|
|
64
|
+
* resourceUri: 'https://mcp.example.com',
|
|
65
|
+
* authorizationServers: ['https://auth.example.com'],
|
|
66
|
+
* tokenIntrospectionEndpoint: '...',
|
|
67
|
+
* tokenIntrospectionClientId: '...',
|
|
68
|
+
* tokenIntrospectionClientSecret: process.env.INTROSPECTION_SECRET,
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* server.start();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function setupOAuthAuth(app, config, path = '/mcp') {
|
|
75
|
+
configureServerAuth(app, config, {
|
|
76
|
+
protectRoutes: [path],
|
|
77
|
+
});
|
|
78
|
+
console.log(`✅ OAuth 2.1 auth enabled on ${path}`);
|
|
79
|
+
console.log(` Resource URI: ${config.resourceUri}`);
|
|
80
|
+
console.log(` Auth Servers: ${config.authorizationServers.join(', ')}`);
|
|
81
|
+
console.log(` Scopes: ${config.scopesSupported?.join(', ') || 'none'}`);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate test credentials (for development)
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const creds = generateTestCredentials();
|
|
89
|
+
* console.log('JWT Secret:', creds.jwtSecret);
|
|
90
|
+
* console.log('API Key:', creds.apiKey);
|
|
91
|
+
* console.log('Sample Token:', creds.sampleToken);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function generateTestCredentials(options) {
|
|
95
|
+
const jwtSecret = generateAPIKey('jwt_secret');
|
|
96
|
+
const apiKey = generateAPIKey(options?.apiKeyPrefix);
|
|
97
|
+
const sampleToken = generateJWT({
|
|
98
|
+
secret: jwtSecret,
|
|
99
|
+
payload: {
|
|
100
|
+
sub: 'test-user',
|
|
101
|
+
scopes: ['mcp:read', 'mcp:write'],
|
|
102
|
+
},
|
|
103
|
+
expiresIn: '1h',
|
|
104
|
+
audience: options?.jwtAudience,
|
|
105
|
+
issuer: options?.jwtIssuer,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
jwtSecret,
|
|
109
|
+
apiKey,
|
|
110
|
+
apiKeyHashed: hashAPIKey(apiKey),
|
|
111
|
+
sampleToken,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Print auth setup instructions
|
|
116
|
+
*/
|
|
117
|
+
export function printAuthSetupInstructions(type) {
|
|
118
|
+
console.log('\n╔══════════════════════════════════════════════════════════════╗');
|
|
119
|
+
console.log('║ AUTH SETUP INSTRUCTIONS ║');
|
|
120
|
+
console.log('╚══════════════════════════════════════════════════════════════╝\n');
|
|
121
|
+
if (type === 'jwt') {
|
|
122
|
+
console.log('📝 Simple JWT Authentication Setup:\n');
|
|
123
|
+
console.log('1. Generate a secret:');
|
|
124
|
+
console.log(' const creds = generateTestCredentials();');
|
|
125
|
+
console.log(' console.log(creds.jwtSecret);\n');
|
|
126
|
+
console.log('2. Add to .env:');
|
|
127
|
+
console.log(' JWT_SECRET=jwt_secret_...\n');
|
|
128
|
+
console.log('3. Enable in server:');
|
|
129
|
+
console.log(' setupJWTAuth(server.app, {');
|
|
130
|
+
console.log(' secret: process.env.JWT_SECRET!,');
|
|
131
|
+
console.log(' audience: "my-mcp-server",');
|
|
132
|
+
console.log(' });\n');
|
|
133
|
+
console.log('4. Generate tokens:');
|
|
134
|
+
console.log(' const token = generateJWT({');
|
|
135
|
+
console.log(' secret: process.env.JWT_SECRET!,');
|
|
136
|
+
console.log(' payload: { sub: "user123" },');
|
|
137
|
+
console.log(' expiresIn: "1h",');
|
|
138
|
+
console.log(' });\n');
|
|
139
|
+
console.log('5. Use in client:');
|
|
140
|
+
console.log(' Authorization: Bearer <token>\n');
|
|
141
|
+
}
|
|
142
|
+
if (type === 'apikey') {
|
|
143
|
+
console.log('📝 API Key Authentication Setup:\n');
|
|
144
|
+
console.log('1. Generate API keys:');
|
|
145
|
+
console.log(' const key1 = generateAPIKey();');
|
|
146
|
+
console.log(' const key2 = generateAPIKey();\n');
|
|
147
|
+
console.log('2. Add to .env:');
|
|
148
|
+
console.log(' API_KEY_1=sk_...');
|
|
149
|
+
console.log(' API_KEY_2=sk_...\n');
|
|
150
|
+
console.log('3. Enable in server:');
|
|
151
|
+
console.log(' setupAPIKeyAuth(server.app, {');
|
|
152
|
+
console.log(' keys: [');
|
|
153
|
+
console.log(' process.env.API_KEY_1!,');
|
|
154
|
+
console.log(' process.env.API_KEY_2!,');
|
|
155
|
+
console.log(' ],');
|
|
156
|
+
console.log(' });\n');
|
|
157
|
+
console.log('4. Use in client:');
|
|
158
|
+
console.log(' X-API-Key: sk_...\n');
|
|
159
|
+
}
|
|
160
|
+
if (type === 'oauth') {
|
|
161
|
+
console.log('📝 OAuth 2.1 Authentication Setup:\n');
|
|
162
|
+
console.log('1. Deploy an OAuth 2.1 authorization server');
|
|
163
|
+
console.log(' (e.g., Auth0, Keycloak, Azure AD)\n');
|
|
164
|
+
console.log('2. Configure in server:');
|
|
165
|
+
console.log(' setupOAuthAuth(server.app, {');
|
|
166
|
+
console.log(' resourceUri: "https://mcp.example.com",');
|
|
167
|
+
console.log(' authorizationServers: ["https://auth.example.com"],');
|
|
168
|
+
console.log(' tokenIntrospectionEndpoint: "...",');
|
|
169
|
+
console.log(' tokenIntrospectionClientId: "...",');
|
|
170
|
+
console.log(' tokenIntrospectionClientSecret: process.env.SECRET,');
|
|
171
|
+
console.log(' });\n');
|
|
172
|
+
console.log('3. Use the inspector AUTH tab to test\n');
|
|
173
|
+
}
|
|
174
|
+
console.log('═══════════════════════════════════════════════════════════════\n');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Validate auth environment variables
|
|
178
|
+
*/
|
|
179
|
+
export function validateAuthEnv(type) {
|
|
180
|
+
const missing = [];
|
|
181
|
+
if (type === 'jwt') {
|
|
182
|
+
if (!process.env.JWT_SECRET) {
|
|
183
|
+
missing.push('JWT_SECRET');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (type === 'apikey') {
|
|
187
|
+
if (!process.env.API_KEY_1 && !process.env.API_KEY) {
|
|
188
|
+
missing.push('API_KEY_1 or API_KEY');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (type === 'oauth') {
|
|
192
|
+
const required = [
|
|
193
|
+
'OAUTH_RESOURCE_URI',
|
|
194
|
+
'OAUTH_AUTH_SERVER',
|
|
195
|
+
'OAUTH_INTROSPECTION_ENDPOINT',
|
|
196
|
+
'OAUTH_CLIENT_ID',
|
|
197
|
+
'OAUTH_CLIENT_SECRET',
|
|
198
|
+
];
|
|
199
|
+
for (const key of required) {
|
|
200
|
+
if (!process.env[key]) {
|
|
201
|
+
missing.push(key);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
valid: missing.length === 0,
|
|
207
|
+
missing,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=quick-setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quick-setup.js","sourceR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AO;QACL,KAAK,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC;QAC3B,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Express } from 'express';
|
|
2
|
+
import { McpAuthConfig } from './types.js';
|
|
3
|
+
import { requireScopes } from './middleware.js';
|
|
4
|
+
export type { McpAuthConfig } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Server Integration Utilities
|
|
7
|
+
*
|
|
8
|
+
* Easy integration of OAuth 2.1 auth into MCP servers
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Configure authentication for MCP server
|
|
12
|
+
*
|
|
13
|
+
* This adds:
|
|
14
|
+
* 1. Protected Resource Metadata endpoint
|
|
15
|
+
* 2. Authentication middleware to specified routes
|
|
16
|
+
*
|
|
17
|
+
* @param app - Express application
|
|
18
|
+
* @param config - Auth configuration
|
|
19
|
+
* @param protectRoutes - Routes to protect with auth (default: all /mcp routes)
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const app = express();
|
|
24
|
+
*
|
|
25
|
+
* configureServerAuth(app, {
|
|
26
|
+
* resourceUri: 'https://mcp.example.com',
|
|
27
|
+
* authorizationServers: ['https://auth.example.com'],
|
|
28
|
+
* tokenIntrospectionEndpoint: 'https://auth.example.com/oauth/introspect',
|
|
29
|
+
* tokenIntrospectionClientId: 'mcp-server',
|
|
30
|
+
* tokenIntrospectionClientSecret: process.env.INTROSPECTION_SECRET,
|
|
31
|
+
* audience: 'https://mcp.example.com',
|
|
32
|
+
* scopesSupported: ['mcp:read', 'mcp:write']
|
|
33
|
+
* }, {
|
|
34
|
+
* protectRoutes: ['/mcp/*']
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function configureServerAuth(app: Express, config: McpAuthConfig, options?: {
|
|
39
|
+
protectRoutes?: string[];
|
|
40
|
+
metadataPath?: string;
|
|
41
|
+
}): void;
|
|
42
|
+
/**
|
|
43
|
+
* Scope-based route protection helper
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const scopes = createScopeGuards(['mcp:read', 'mcp:write', 'mcp:admin']);
|
|
48
|
+
*
|
|
49
|
+
* app.get('/mcp/tools', scopes.read, (req, res) => {
|
|
50
|
+
* // List tools - requires mcp:read
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* app.post('/mcp/tools/execute', scopes.write, (req, res) => {
|
|
54
|
+
* // Execute tool - requires mcp:write
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* app.delete('/mcp/resources', scopes.admin, (req, res) => {
|
|
58
|
+
* // Delete resource - requires mcp:admin
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function createScopeGuards(scopeConfig: {
|
|
63
|
+
read?: string[];
|
|
64
|
+
write?: string[];
|
|
65
|
+
admin?: string[];
|
|
66
|
+
[key: string]: string[] | undefined;
|
|
67
|
+
}): Record<string, ReturnType<typeof requireScopes>>;
|
|
68
|
+
/**
|
|
69
|
+
* Create standard MCP scope configuration
|
|
70
|
+
*
|
|
71
|
+
* Returns scope guards for common MCP operations:
|
|
72
|
+
* - read: List tools, resources, prompts
|
|
73
|
+
* - execute: Execute tools, get prompts
|
|
74
|
+
* - write: Modify resources
|
|
75
|
+
* - admin: Server configuration
|
|
76
|
+
*
|
|
77
|
+
* @param scopePrefix - Scope prefix (default: 'mcp')
|
|
78
|
+
*/
|
|
79
|
+
export declare function createMCPScopeGuards(scopePrefix?: string): Record<string, import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>>;
|
|
80
|
+
/**
|
|
81
|
+
* Generate suggested scopes for MCP server
|
|
82
|
+
*
|
|
83
|
+
* Returns standard scope definitions for MCP operations
|
|
84
|
+
*/
|
|
85
|
+
export declare function getStandardMCPScopes(scopePrefix?: string): {
|
|
86
|
+
scopes: string[];
|
|
87
|
+
descriptions: Record<string, string>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Helper to validate auth configuration
|
|
91
|
+
*/
|
|
92
|
+
export declare function validateAuthConfig(config: McpAuthConfig): {
|
|
93
|
+
valid: boolean;
|
|
94
|
+
errors: string[];
|
|
95
|
+
warnings: string[];
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=server-integration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-integration.d.ts","sourceRoot":"","sources":["../../src/auth/server-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAqB,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAwB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGtE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,OAAO,EACZ,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE;IACR,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACA,IAAI,CA0BN;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE;IAC7C,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;CACrC,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAUnD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,GAAE,MAAc,gKAO/D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,GAAE,MAAc,GAAG;IACjE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,CAgBA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,aAAa,GAAG;IACzD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAkEA"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { createProtectedResourceMetadata } from './server-metadata.js';
|
|
2
|
+
import { createAuthMiddleware, requireScopes } from './middleware.js';
|
|
3
|
+
/**
|
|
4
|
+
* Server Integration Utilities
|
|
5
|
+
*
|
|
6
|
+
* Easy integration of OAuth 2.1 auth into MCP servers
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Configure authentication for MCP server
|
|
10
|
+
*
|
|
11
|
+
* This adds:
|
|
12
|
+
* 1. Protected Resource Metadata endpoint
|
|
13
|
+
* 2. Authentication middleware to specified routes
|
|
14
|
+
*
|
|
15
|
+
* @param app - Express application
|
|
16
|
+
* @param config - Auth configuration
|
|
17
|
+
* @param protectRoutes - Routes to protect with auth (default: all /mcp routes)
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const app = express();
|
|
22
|
+
*
|
|
23
|
+
* configureServerAuth(app, {
|
|
24
|
+
* resourceUri: 'https://mcp.example.com',
|
|
25
|
+
* authorizationServers: ['https://auth.example.com'],
|
|
26
|
+
* tokenIntrospectionEndpoint: 'https://auth.example.com/oauth/introspect',
|
|
27
|
+
* tokenIntrospectionClientId: 'mcp-server',
|
|
28
|
+
* tokenIntrospectionClientSecret: process.env.INTROSPECTION_SECRET,
|
|
29
|
+
* audience: 'https://mcp.example.com',
|
|
30
|
+
* scopesSupported: ['mcp:read', 'mcp:write']
|
|
31
|
+
* }, {
|
|
32
|
+
* protectRoutes: ['/mcp/*']
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function configureServerAuth(app, config, options) {
|
|
37
|
+
const metadataPath = options?.metadataPath || '/.well-known/oauth-protected-resource';
|
|
38
|
+
const protectRoutes = options?.protectRoutes || ['/mcp/*'];
|
|
39
|
+
// 1. Add Protected Resource Metadata endpoint
|
|
40
|
+
app.get(metadataPath, (req, res) => {
|
|
41
|
+
const metadata = createProtectedResourceMetadata(config.resourceUri, config.authorizationServers, config.scopesSupported);
|
|
42
|
+
res.json(metadata);
|
|
43
|
+
});
|
|
44
|
+
// 2. Apply auth middleware to protected routes
|
|
45
|
+
const authMiddleware = createAuthMiddleware(config);
|
|
46
|
+
for (const route of protectRoutes) {
|
|
47
|
+
app.use(route, authMiddleware);
|
|
48
|
+
}
|
|
49
|
+
console.log(`🔐 OAuth 2.1 authentication configured for ${config.resourceUri}`);
|
|
50
|
+
console.log(` Authorization servers: ${config.authorizationServers.join(', ')}`);
|
|
51
|
+
console.log(` Protected routes: ${protectRoutes.join(', ')}`);
|
|
52
|
+
console.log(` Metadata endpoint: ${metadataPath}`);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Scope-based route protection helper
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const scopes = createScopeGuards(['mcp:read', 'mcp:write', 'mcp:admin']);
|
|
60
|
+
*
|
|
61
|
+
* app.get('/mcp/tools', scopes.read, (req, res) => {
|
|
62
|
+
* // List tools - requires mcp:read
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* app.post('/mcp/tools/execute', scopes.write, (req, res) => {
|
|
66
|
+
* // Execute tool - requires mcp:write
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* app.delete('/mcp/resources', scopes.admin, (req, res) => {
|
|
70
|
+
* // Delete resource - requires mcp:admin
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export function createScopeGuards(scopeConfig) {
|
|
75
|
+
const guards = {};
|
|
76
|
+
for (const [name, scopes] of Object.entries(scopeConfig)) {
|
|
77
|
+
if (scopes && scopes.length > 0) {
|
|
78
|
+
guards[name] = requireScopes(...scopes);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return guards;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create standard MCP scope configuration
|
|
85
|
+
*
|
|
86
|
+
* Returns scope guards for common MCP operations:
|
|
87
|
+
* - read: List tools, resources, prompts
|
|
88
|
+
* - execute: Execute tools, get prompts
|
|
89
|
+
* - write: Modify resources
|
|
90
|
+
* - admin: Server configuration
|
|
91
|
+
*
|
|
92
|
+
* @param scopePrefix - Scope prefix (default: 'mcp')
|
|
93
|
+
*/
|
|
94
|
+
export function createMCPScopeGuards(scopePrefix = 'mcp') {
|
|
95
|
+
return createScopeGuards({
|
|
96
|
+
read: [`${scopePrefix}:read`],
|
|
97
|
+
execute: [`${scopePrefix}:read`, `${scopePrefix}:execute`],
|
|
98
|
+
write: [`${scopePrefix}:read`, `${scopePrefix}:write`],
|
|
99
|
+
admin: [`${scopePrefix}:admin`],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Generate suggested scopes for MCP server
|
|
104
|
+
*
|
|
105
|
+
* Returns standard scope definitions for MCP operations
|
|
106
|
+
*/
|
|
107
|
+
export function getStandardMCPScopes(scopePrefix = 'mcp') {
|
|
108
|
+
const scopes = [
|
|
109
|
+
`${scopePrefix}:read`,
|
|
110
|
+
`${scopePrefix}:execute`,
|
|
111
|
+
`${scopePrefix}:write`,
|
|
112
|
+
`${scopePrefix}:admin`,
|
|
113
|
+
];
|
|
114
|
+
const descriptions = {
|
|
115
|
+
[`${scopePrefix}:read`]: 'Read access to tools, resources, and prompts',
|
|
116
|
+
[`${scopePrefix}:execute`]: 'Execute tools and get prompts',
|
|
117
|
+
[`${scopePrefix}:write`]: 'Modify resources and server state',
|
|
118
|
+
[`${scopePrefix}:admin`]: 'Administrative access to server configuration',
|
|
119
|
+
};
|
|
120
|
+
return { scopes, descriptions };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Helper to validate auth configuration
|
|
124
|
+
*/
|
|
125
|
+
export function validateAuthConfig(config) {
|
|
126
|
+
const errors = [];
|
|
127
|
+
const warnings = [];
|
|
128
|
+
// Required fields
|
|
129
|
+
if (!config.resourceUri) {
|
|
130
|
+
errors.push('resourceUri is required');
|
|
131
|
+
}
|
|
132
|
+
if (!config.authorizationServers || config.authorizationServers.length === 0) {
|
|
133
|
+
errors.push('At least one authorization server is required');
|
|
134
|
+
}
|
|
135
|
+
// Token validation method
|
|
136
|
+
const hasIntrospection = !!config.tokenIntrospectionEndpoint;
|
|
137
|
+
const hasJWT = !!config.jwksUri;
|
|
138
|
+
if (!hasIntrospection && !hasJWT) {
|
|
139
|
+
errors.push('Either tokenIntrospectionEndpoint or jwksUri must be configured');
|
|
140
|
+
}
|
|
141
|
+
// Introspection credentials
|
|
142
|
+
if (hasIntrospection) {
|
|
143
|
+
if (!config.tokenIntrospectionClientId) {
|
|
144
|
+
warnings.push('tokenIntrospectionClientId not set - introspection may fail');
|
|
145
|
+
}
|
|
146
|
+
if (!config.tokenIntrospectionClientSecret) {
|
|
147
|
+
warnings.push('tokenIntrospectionClientSecret not set - introspection may fail');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// JWT validation
|
|
151
|
+
if (hasJWT) {
|
|
152
|
+
if (!config.audience) {
|
|
153
|
+
errors.push('audience is required for JWT validation (prevents confused deputy attacks)');
|
|
154
|
+
}
|
|
155
|
+
if (!config.issuer) {
|
|
156
|
+
warnings.push('issuer not set - JWT validation may be less strict');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Audience (critical for security)
|
|
160
|
+
if (!config.audience) {
|
|
161
|
+
warnings.push('audience not set - tokens will not be validated for this resource. ' +
|
|
162
|
+
'This is a security risk (confused deputy attacks).');
|
|
163
|
+
}
|
|
164
|
+
// HTTPS
|
|
165
|
+
if (config.requireHttps !== false && process.env.NODE_ENV === 'production') {
|
|
166
|
+
try {
|
|
167
|
+
const url = new URL(config.resourceUri);
|
|
168
|
+
if (url.protocol !== 'https:') {
|
|
169
|
+
errors.push('resourceUri must use HTTPS in production');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
errors.push('resourceUri is not a valid URL');
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
valid: errors.length === 0,
|
|
178
|
+
errors,
|
|
179
|
+
warnings,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=server-integration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-integration.js","sourceRoot":"","sources":["../../src/auth/server-integration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKtE;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAY,EACZ,MAAqB,EACrB,OAGC;IAED,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,uCAAuC,CAAC;IACtF,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,IAAI,CAAC,QAAQ,CAAC,CAAC;IAE3D,8CAA8C;IAC9C,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,GAAY,EAAE,GAAa,EAAE,EAAE;QACpD,MAAM,QAAQ,GAAG,+BAA+B,CAC9C,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,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,CAAC,gCAAgC,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;QACN,QAAQ;KACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ProtectedResourceMetadata } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Protected Resource Metadata (RFC 9728)
|
|
4
|
+
*
|
|
5
|
+
* MCP servers MUST implement this to advertise their authorization servers
|
|
6
|
+
* to MCP clients. This enables automatic discovery of auth configuration.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Create protected resource metadata document
|
|
10
|
+
*
|
|
11
|
+
* @param resourceUri - The URI of this MCP server
|
|
12
|
+
* @param authorizationServers - Array of authorization server issuer URLs
|
|
13
|
+
* @param scopesSupported - Optional: scopes this resource supports
|
|
14
|
+
*/
|
|
15
|
+
export declare function createProtectedResourceMetadata(resourceUri: string, authorizationServers: string[], scopesSupported?: string[]): ProtectedResourceMetadata;
|
|
16
|
+
/**
|
|
17
|
+
* Get well-known URI for protected resource metadata
|
|
18
|
+
* Per RFC 9728, can be at:
|
|
19
|
+
* 1. Resource path: /.well-known/oauth-protected-resource{path}
|
|
20
|
+
* 2. Root: /.well-known/oauth-protected-resource
|
|
21
|
+
*/
|
|
22
|
+
export declare function getWellKnownMetadataUris(resourceUrl: URL): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Generate WWW-Authenticate header value for 401 responses
|
|
25
|
+
* Per RFC 6750 and MCP spec
|
|
26
|
+
*
|
|
27
|
+
* @param resourceMetadataUrl - URL to protected resource metadata
|
|
28
|
+
* @param scope - Optional: required scopes for this request
|
|
29
|
+
* @param error - Optional: error code (invalid_token, insufficient_scope, etc.)
|
|
30
|
+
* @param errorDescription - Optional: human-readable error description
|
|
31
|
+
*/
|
|
32
|
+
export declare function generateWWWAuthenticateHeader(options: {
|
|
33
|
+
resourceMetadataUrl?: string;
|
|
34
|
+
scope?: string;
|
|
35
|
+
error?: string;
|
|
36
|
+
errorDescription?: string;
|
|
37
|
+
realm?: string;
|
|
38
|
+
}): string;
|
|
39
|
+
/**
|
|
40
|
+
* Parse WWW-Authenticate header
|
|
41
|
+
* Extracts Bearer auth challenge parameters
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseWWWAuthenticateHeader(headerValue: string): {
|
|
44
|
+
scheme: string;
|
|
45
|
+
realm?: string;
|
|
46
|
+
scope?: string;
|
|
47
|
+
resourceMetadata?: string;
|
|
48
|
+
error?: string;
|
|
49
|
+
errorDescription?: string;
|
|
50
|
+
} | null;
|
|
51
|
+
//# sourceMappingURL=server-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-metadata.d.ts","sourceRoot":"","sources":["../../src/auth/server-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;GAKG;AAEH;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,MAAM,EACnB,oBAAoB,EAAE,MAAM,EAAE,EAC9B,eAAe,CAAC,EAAE,MAAM,EAAE,GACzB,yBAAyB,CAO3B;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,GAAG,GAAG,MAAM,EAAE,CAcnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE;IACrD,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CAwBT;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,IAAI,CAoCP"}
|